2012-10-13 110 views
1

我需要幫助的所有字段訪問數據,原始數據由JSON對象提供從如何訪問數據的二維數組中的PHP

這個數組$已解碼是的print_r($距離)結果:

Array ([0] => Array ([numberOfResult] => 1 [idUsager] => 1 [idUnique] => 1880e784 [codeLanguage] => fr [language] => Français [idCountry] => 66 [country] => Québec - Montréal [photo] => /usagers/1/1880e784/1880e784.png [pseudo] => PLATiNUM2727 [firstName] => Bedard [lastName] => Gabriel [ddn] => 1994-08-19 [mindText] => new status [compteVerifie] => 2012-01-03 [online] => 10 [onlineDescription] => En ligne [iSearch] => 3 [iSearchDescription] => Amis [level] => 5000 [levelDescription] => Administrateur [lookingFor] => partys & événements, Sexe, Autre..., [myInterest] => nature [myFavoriteBooks] => Dan Brown [myFavoriteMovies] => action [myFavoriteMusic] => Trance4Ever [myFavoriteTvShows] => CSI Miami [description] => description [dateDescrWaitingApproval] => 2012-07-17 17:38:23 [dateDescrApprouved] => 0000-00-00 00:00:00 [descriptionWaiting] => test [lastModification] => 2012-10-06 20:51:59 [bodyType] => Costaud [carOwner] => Non [homeOwner] => Non [smoking] => Non [drinking] => Socialement [drug] => Rarement [eyeColor] => Brun pâle [hairColor] => Bruns pâles [education] => BACC Universitaire gradué [height] => 5'7" (170 cm) [weight] => 196 lbs (89 kg) [relationshipStatus] => Célibataire [sexualOrientation] => Préfère ne pas dire [zodiac] => Capricorne [job] => Informatique))` 

如何訪問[numberOfResult]或[firstName]例如?

+4

請格式化您的問題。 –

+1

此外,「多維」,而不是「雙」。 –

+1

@AlexLunix:「Bidimensional」是精確的。 =) –

回答

2
$from[0]['numberOfResult'] 

                                                                 

+0

謝謝你的快速答案! – LiTHiUM2525

0

[numberOfResult]使用本

echo $from[0]['numberOfResult']; 

[firstName]使用本

echo $from[0]['firstName']; 
1

這是2D陣列的示例表,

enter image description here

代碼訪問和顯示上面的表格在PHP到HTML。

<?php 
echo "<h1>Manual access to each element</h1>"; 

echo $shop[0][0]." costs ".$shop[0][2]." and you get ".$shop[0][2]."<br />"; 
echo $shop[1][0]." costs ".$shop[1][3]." and you get ".$shop[1][2]."<br />"; 
echo $shop[2][0]." costs ".$shop[2][4]." and you get ".$shop[2][2]."<br />"; 

echo "<h1>Using loops to display array elements</h1>"; 

echo "<ol>"; 
for ($row = 0; $row < 3; $row++) 
{ 
    echo "<li><b>The row number $row</b>"; 
    echo "<ul>"; 

    for ($col = 0; $col < 3; $col++) 
    { 
     echo "<li>".$shop[$row][$col]."</li>"; 
    } 

    echo "</ul>"; 
    echo "</li>"; 
} 
echo "</ol>"; 
?> 

參考Link

我希望這會幫助你。謝謝。