2014-04-29 201 views
0

我有一個多陣列,如何訪問各個項目,即「個人資料標題」,是有辦法,我可以遍歷數組變量賦值給每個數組值例如PHP多維數組

$ firstarray - >名稱 $ firstarray-> HTML

$ secondarray-> TYPEID

感謝

array(4) { 
     [0]=> 
     array(4) { 
     ["name"]=> 
     string(13) "profile title" 
     ["html"]=> 
     string(52) "<h2 class="entry-title" id="title">Your Profile</h2>" 
     ["typeId"]=> 
     string(1) "1" 
     } 
     [1]=> 
     array(4) { 
     ["name"]=> 
     string(8) "username" 
     ["html"]=> 
     string(145) "<fieldset disabled><br><label for="nameinput">Username</label><input type="text" id="userName"class="form-control" placeholder="" ></fieldset><p>" 
     ["typeId"]=> 
     string(1) "1" 
     } 

回答

3

假設你的數組稱爲$ firstarray:

foreach ($firstarray as $row) 
{ 
    echo $row['name']; // or $row->name; 
} 
+0

感謝您的幫助 – user3524311

0

文森特的答案應該可以幫助您訪問每個元素。然而,爲了給它們,你需要使用array_push

`array_push`( $firstarray, array('key'=>'value','key1'=>'value1') ); 


OR 


$firstarray[0]['key'] = 'something'; 
$firstarray[0]['key1'] = 'something else'; 

$firstarray[1]['key'] = 'something'; 
$firstarray[1]['key1'] = 'something else'; 

etc.. 


OR 

$firstarray[0] = $secondarray1; 
$firstarray[1] = $secondarray2; 

etc.. 
+0

感謝這有助於 – user3524311

+0

如果幫助,考慮upvoting或標記爲已回答。謝謝! –