循环遍历二维数组 [英] Loop through a two-dimensional array
本文介绍了循环遍历二维数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个看起来像这样的数组:
I have an array that looks like this:
$array = array(
array(
"http://google.com",
"Google"
),
array(
"http://yahoo.com",
"Yahoo"
)
);
遍历它的最简单方法是什么.类似的东西:
What is the simplest way to loop through it. Something like:
foreach ($array as $arr) {
// help
}
我如何定位键,例如,我想做:
How do I target keys, for example, I want to do:
foreach ($array as $arr) {
echo '<a href" $key1 ">';
echo ' $key2 </a>';
}
推荐答案
为了回显这些位,您必须在每个数组中选择它们的索引 -
In order to echo out the bits you have to select their index in each array -
foreach($array as $arr){
echo '<a href="'.$arr[0].'">'.$arr[1].'</a>';
}
这是一个示例.
这篇关于循环遍历二维数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文