具有自定义键值的多维数组
嗨,我有一个问题,我有两个使用 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"> $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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
创建数组时,手动设置键并在每次添加新项目时增加它,如下所示:
When you create array, set the key manually and increament it each time you add a new item like this:
你想要的似乎非常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.
试试这个:
Try this: