2014-11-23 68 views
0

我有這個陣列如何從數組中回顯數據?

Array 
(
[first_information] => Array 
    (
     [0] => 10 
     [1] => 12 
    ) 

[rows] => 1 
[0] => Array 
    (
     [data_1] => 1 
     [data_2] => 2 
     [data_3] => 3 
     [data_4] => 4 
     [data_5] => 5 
    ) 

我怎麼只顯示[first_information]內容的。

我試圖與此代碼

foreach($row['first_information'] as $first) 
    echo $first; 

但僅示出了「12」,這是該陣列的第二元件。

預先感謝您。

+1

這應該工作,('的foreach($行[ 'first_information']爲$第一){回聲$第一;}')。你是否100%確定你的數組看起來像那樣? – Darren 2014-11-23 23:53:42

+0

解決! echo $ row ['first_information'] [0]。' 」。$行[ 'first_information'] [1] – user3104718 2014-11-24 00:00:09

回答

1

你在做錯事(沒有問題,可能是錯誤的var)。下面按預期(http://codepad.org/NDxhEBdY)工作的代碼:

$row = array(
    'first_information' => Array(10,12), 
    'rows' => 1, 
    0 => Array(
     'data_1' => 1, 
     'data_2' => 2, 
     'data_3' => 3, 
     'data_4' => 4, 
     'data_5' => 5 
    ) 
); 

foreach($row['first_information'] as $first) 
    echo $first;