2016-12-01 17 views
-5

我想遍歷下面的數組。如何通過以下php數組循環?

array(2) { 
    [0]=> array(6) { 
     [0]=> string(10) "excel_id " 
     [1]=> string(12) "excel_name " 
     [2]=> string(11) "excel_email" 
     [3]=> string(13) "excel_address" 
     [4]=> string(12) "excel_giveby" 
     [5]=> string(16) "excel_accesories" 
    } 
    [1]=> array(6) { 
     [0]=> float(111) 
     [1]=> string(10) "sh1exname1" 
     [2]=> string(11) "sh1exemail1" 
     [3]=> string(12) "sh1exaddress" 
     [4]=> string(12) "sh1exgivenby" 
     [5]=> string(16) "sh1exaccesorries" 
    }  
} 

任何人都可以幫助我嗎?

+0

嘗試使用'在啓動 – RomanPerekhrest

+0

foreach'環問一個問題之前,請點擊這裏:HTTP://計算器.com/help/how-to-ask –

+0

你甚至試過看數組的PHP手冊嗎? – NaeiKinDus

回答

0

試試這個:

foreach ($main_array as $outer_entry){ 

    foreach($outer_entry as $entity){ 
     print_r($entity); 
    } 

} 
2

如果你嘗試過所有你應該已經發現的foreach任何東西。 這將遍歷所有的數組值。 你可以簡單地通過一個多維數組循環利用這樣一個多維的foreach:

foreach($array as $parentValue) 
{ 
    foreach($parentValue as $childValue) 
    { 
     // your code 
    } 
}