显示具有顺序索引的 php 数组
我有一个问题,我有两个数组,1 个是使用 php 爆炸函数创建的。我想要的是显示数组中每个单词的数字。下面是我正在使用的代码。我想要它的原因是我可以将 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");
检查第 15 行 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++;
}
I have a problem I have two arrays, 1 created using php explode function. What I want is to display the number for each word in the array. Below is the code I'm using. 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");
check line 15
p.s I am not a pro at php and I definitely 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)
在 foreach 循环中使用键:
http://php .net/manual/en/language.types.array.php
Use keys in your foreach loop:
http://php.net/manual/en/language.types.array.php
据我理解您的问题,您应该使用与此类似的代码:
其中
$dictionary
是一个包含您能识别的所有单词的数组,而$suraWords
是包含以下内容的数组:爆炸的苏拉。通过这种方式,您的所有单词都会被翻译为相应的文件名(尽管我不对该解决方案的效率做出任何假设)。
As far I undestand your question, you should use a code similar to this:
where
$dictionary
is an array with all the word you would recognize and$suraWords
is the array containing the exploded sura.In this way all your words are translated to the corresponding filename (though I don't assume nothing on efficiency of this solution).
为什么不直接对三个数组进行 array_merge 呢?您是否需要将信息放在单独的数组中?
这样您就可以根据需要获得所有顺序键。
Why don't you just do an array_merge of the three arrays? Is there any reason you need to have the information in separate arrays?
That way you would have all the sequential keys as you need them.