循环遍历PHP数组

时间:2013-10-15 21:28:49

标签: php arrays loops

我有一个数组的数组,格式如下:

$list = [ ["fdsa","1","fdsa"],["sadf","0","asdf"],["frfrf","0","sadfdsf"] ]

如何遍历每个值?

2 个答案:

答案 0 :(得分:3)

使用RecursiveIteratorIterator

foreach(new RecursiveIteratorIterator(new RecursiveArrayIterator($list)) as $item){
        var_dump($item);
}

string(4) "fdsa"
string(1) "1"
string(4) "fdsa"
string(4) "sadf"
string(1) "0"
string(4) "asdf"
string(5) "frfrf"
string(1) "0"
string(7) "sadfdsf"

......除非你想要它更有条理......

答案 1 :(得分:-2)

尝试:

$array = array(array("!","Hello","World"));
foreach($array as $key){
    $myvar = $key[0];
    $myvar2 = $key[1];
    $myvar3 = $key[2];
}

已更新!

希望它有所帮助!