$sociallinkflied1 = $row['sociallinkflied'];
$codes = explode(',', $sociallinkflied1);
$sociallinktitle = $row['sociallink'];
$names = explode(',', $sociallinktitle);
$sociallinkflied = $row['sociallinkflied'];
$sociallinkflied1 = explode(',', $sociallinkflied);
foreach( $codes as $index => $code ){
echo '<a href='.$names[$index].' target=" '._blank.'" style="margin: 10px;">
<i class="fa '.$code.'"></i>'.$sociallinkflied1[$index].'
</a>';
}
如何在每个循环中使用这3个数组。请帮助我解决此问题
答案 0 :(得分:0)
我想您是在问如何在PHP中同时遍历多个数组。您认为需要通过索引引用数组项是正确的。
但是您需要使用for
循环,因为索引是一个数字。并且您必须按索引引用数组的所有:
$names = array("Tom", "Dick", "Harry");
$codes = array("aaa", "bbb", "ccc");
$links = array("/foo", "/bar", "/qux");
$number_of_items = count($names); # could use any of the arrays, if they are all the same size
for ($index = 0; $index < $number_of_items; $index++) {
echo '<a href="'.$links[$index].'">
<i class="fa '.$codes[$index].'"></i>'.$names[$index].'
</a>';
echo "\n";
}
祝您程序顺利!