具有自定义键值的多维数组

发布于 2024-11-11 02:49:40 字数 2086 浏览 9 评论 0原文

嗨,我有一个问题,我有两个使用 phpexplode 函数创建的数组 1,我希望它显示数组中每个单词的数字。我想要它的原因是我可以将 mp3 文件链接到列表中的每个单词。 mp3 的文件链接格式是链接: 0000001.mp3 、 0000002.mp3 等,

目前数组为每个数组生成零的起始键值:

$a1 = array(0=>"Cat",1=>"Dog",2=>"Horse",3=>"House");
$a2 = array(0=>"Bird",1=>"Rat",2=>"Fish");
$a3 = array(0=>"Horse",1=>"Dog",2=>"Bird");

//////// 我希望数组具有继续的键这样我就可以将它们链接到 mp3 文件,例如

$a1 = array(0=>"Cat",1=>"Dog",2=>"Horse",3=>"House");
$a2 = array(4=>"Bird",5=>"Rat",6=>"Fish");
$a3 = array(7=>"Horse",8=>"Dog",9=>"Bird");

ps 我不是 php 专业人士,我绝对知道 php 代码中有一些错误。 http://www.deen-ul-islam.org/quran-player /古兰经.php

foreach ($suraText as $aya)
        {
            $trans = $transText[$ayaNum- 1];
            // remove bismillahs, except for suras 1 and 9
            if (!$showBismillah && $ayaNum == 1 && $sura !=1 && $sura !=9)
                $aya = preg_replace('/^(([^ ]+ ){4})/u', '', $aya);
            // display waqf marks in different style
           // $aya = preg_replace('/ ([ۖ-۩])/u', '<span class="sign">&nbsp;$1</span>', $aya);
$surah2 = leading_zeros($sura, 3);
$ayaNum2 = leading_zeros($ayaNum, 3);
            $aya = explode(' ',$aya);
            echo "<div class=aya>";
            echo "<div class=quran><a href='http://www.everyayah.com/data/Ghamadi_40kbps/$surah2$ayaNum2.mp3' class='sm2_link'><span class=ayaNum>$ayaNum. </span></a>";
            foreach($aya as $key => $aya) { 
            $key = $key+1; ?>
            <a href="http://audio.allahsquran.com/wbw/<?php echo $key ?>.mp3" class="sm2_link"><span class="word"><?php echo $aya ?></span></a>
            <?php }

            echo  "</div>";
            //echo "<div class=trans>$trans </div>";
            echo "</div>";
            $ayaNum++;
        }

hi i have a problem i have two arrays 1 created using php explode function, what i want it to display the number for each word in the array. the reason i want it so that i can link a mp3 file to each word in the list. the file link format to the mp3 are link this: 0000001.mp3 , 0000002.mp3 etc

currently the arrays are producing starting key values of zero for every array:

$a1 = array(0=>"Cat",1=>"Dog",2=>"Horse",3=>"House");
$a2 = array(0=>"Bird",1=>"Rat",2=>"Fish");
$a3 = array(0=>"Horse",1=>"Dog",2=>"Bird");

//////// i want the arrays to have keys that continue so that i can link them to a mp3 file e.g

$a1 = array(0=>"Cat",1=>"Dog",2=>"Horse",3=>"House");
$a2 = array(4=>"Bird",5=>"Rat",6=>"Fish");
$a3 = array(7=>"Horse",8=>"Dog",9=>"Bird");

p.s i am not a pro at php i defiantly know there are a couple of mistakes in the php code. http://www.deen-ul-islam.org/quran-player/quran.php

foreach ($suraText as $aya)
        {
            $trans = $transText[$ayaNum- 1];
            // remove bismillahs, except for suras 1 and 9
            if (!$showBismillah && $ayaNum == 1 && $sura !=1 && $sura !=9)
                $aya = preg_replace('/^(([^ ]+ ){4})/u', '', $aya);
            // display waqf marks in different style
           // $aya = preg_replace('/ ([ۖ-۩])/u', '<span class="sign"> $1</span>', $aya);
$surah2 = leading_zeros($sura, 3);
$ayaNum2 = leading_zeros($ayaNum, 3);
            $aya = explode(' ',$aya);
            echo "<div class=aya>";
            echo "<div class=quran><a href='http://www.everyayah.com/data/Ghamadi_40kbps/$surah2$ayaNum2.mp3' class='sm2_link'><span class=ayaNum>$ayaNum. </span></a>";
            foreach($aya as $key => $aya) { 
            $key = $key+1; ?>
            <a href="http://audio.allahsquran.com/wbw/<?php echo $key ?>.mp3" class="sm2_link"><span class="word"><?php echo $aya ?></span></a>
            <?php }

            echo  "</div>";
            //echo "<div class=trans>$trans </div>";
            echo "</div>";
            $ayaNum++;
        }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

金橙橙 2024-11-18 02:49:40

创建数组时,手动设置键并在每次添加新项目时增加它,如下所示:

$i = 0;
$a1=array(0=>"Cat",++$i=>"Dog",++$i=>"Horse",++$i=>"House");

When you create array, set the key manually and increament it each time you add a new item like this:

$i = 0;
$a1=array(0=>"Cat",++$i=>"Dog",++$i=>"Horse",++$i=>"House");
赢得她心 2024-11-18 02:49:40

你想要的似乎非常hacky,但你可能想看看array_merge()这样你就可以将两个数组合并为一个。

What you want seems very hacky but you might want to take a look at array_merge() so you can merge your two arrays into one.

唐婉 2024-11-18 02:49:40

试试这个:

$array = array_merge($a1, $a2, $a3);

$a1 = array_slice($array, 0, 4, true);
$a2 = array_slice($array, 3, 3, true);
$a3 = array_slice($array, 6, 3, true);

Try this:

$array = array_merge($a1, $a2, $a3);

$a1 = array_slice($array, 0, 4, true);
$a2 = array_slice($array, 3, 3, true);
$a3 = array_slice($array, 6, 3, true);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文