Printing an assosiative array sorted by key
i use this code to get info about friends
<?php
$fql = "SELECT uid, name, pic_square FROM user WHERE uid = me() OR uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) ";
$fUIDS = $facebook->api(array(
'method' => 'fql.query',
'query' =>$fql,
));
print_r($response);
?>
now i need to show the result in this way
echo '<img src="'.$response['pic_square'].'"/>';
but it did not worked so i did this
$fql = "SELECT pic_square FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) ";开发者_如何学运维
$fPics = $facebook->api(array(
'method' => 'fql.query',
'query' =>$fql,
));
$i=count($fPics);
echo 'Total '.$i.' entries found !<br/>'; // this lines shows 10 as expected :)
for ($x=0;$x<$i;$x++)
echo '<img src="'.$fPIcs[$x].'"/>';
now it shows Array
10 times, what is wrong ?
When PHP prints Array
, that means it tried to turn an array into a string.
It is very likely that $fPics
is an array of arrays, not an array of strings.
Try calling print_r($fPics)
, I bet you'll see that each element is actually an array with a single key, pic_square
, and a single value -- the URL to the image, which is what you want.
If so, this means that your loop can be changed to reference that array element:
foreach($fPics as $row) {
echo '<img src="', htmlspecialchars($row['pic_square']), '">';
}
possibly it's cause thats is multidimensional array. To make sure use following methods: print_r, var_dump() or var_export()
Theres show your variable consist of.
精彩评论