可能有一種非常簡單的方法可以做到這一點,但我無法解決這個問題。PHP Array獲取第一項
Array ([0] => Array ([] => US [1] => U.S. [2] => 21 [3] => 34 [4] => 33 [5] => 35 [6] => 39 [7] => 50 [8] => 61) [1] => Array ([] => 79 [1] => 45 [2] => 84 [3] => 89 [4] => 59 [5] => 64 [6] => 34 [7] => 58 [8] => 55) [2] => Array ([] => 63 [1] => 105 [2] => 68 [3] => 62 [4] => 64 [5] => 67 [6] => CL [7] => Chile [8] => 56) [3] => Array ([] => 40 [1] => 40 [2] => 63 [3] => 37 [4] => 57 [5] => 64 [6] => 59 [7] => 53 [8] => 68) [4] => Array ([] => 70 [1] => 66 [2] => 88 [3] => 48 [4] => 76 [5] => 83 [6] => 80 [7] => 53 [8] => 45) [5] => Array ([] => 44 [1] => 51 [2] => 52 [3] => [4] => [5] => [6] => [7] => [8] =>))
這是我的數組。每種方法都有相同數量的對象(9),但是當前在6的數量可能會增加。
我需要得到第一個項目中的每個所以第一我需要的(美國),我堅持,如果我把
echo $array[0][1];
然後我讓我們不過,我需要的第一項(美國)所以我想都
echo $array[0][0];
echo $array[0][];
既不返回一個值。我究竟做錯了什麼?
在你的例子中,沒有第一個數組元素的鍵,我敢肯定這是不可能的 – GrumpyCrouton
@GrumpyCrouton是的,PHP中有一個空的數組鍵;要訪問這樣的元素,那麼必須明確指定一個「空鍵」 - 「$ foo ['']' – CBroe
所以應該像'echo $ array [0] [''];'。這在我看來是不好的數據結構設計... – PeterM