本文實例講述了php實現遍歷多維數組的方法。分享給大家供大家參考,具體如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
$a = array ( 'fruits' => array ( 'a' => 'orange' , 'b' => 'grape' ,c=> 'apple' ), 'numbers' => array (1,2,3,4,5,6), 'holes' => array ( 'first' ,5=> 'second' , 'third' ) ); //第一種: foreach ( $a as $list => $things ){ if ( is_array ( $things )){ foreach ( $things as $newlist => $counter ){ echo "key:" . $newlist . "<br/>" . "value:" . $counter . "<br/>" ; } } } //第二種: function MulitarraytoSingle( $array ){ $temp = array (); if ( is_array ( $array )){ foreach ( $array as $key => $value ) { if ( is_array ( $value )){ MulitarraytoSingle( $value ); } else { $temp []= $value ; } } } } |
希望本文所述對大家php程序設計有所幫助。