我想將json數組打印到它的值中我在json解碼後有下面的數組,我需要在循環中打印它,因爲它有很多項目。 例如,我必須打印值名字,姓氏,我將如何打印它。如何通過json響應打印數組中的值?
stdClass Object ([content] => Array ([0] => stdClass Object ([id] => 5 [firstName] => Ali [lastName] => S [profilePhotoUrl] => https://prn-spe-images.s3-ap-southeast-1.amazonaws.com/user-profiles/5.jpg [handle] => aliya) [1] => stdClass Object ([id] => 69 [handle] => hhtc)) [last] => 1 [totalPages] => 1 [totalElements] => 2 [numberOfElements] => 2 [first] => 1 [sort] => [size] => 10 [number] => 0)
示例代碼我做:
$arrayl = gettviewers($post->id,10);
foreach($arrayl as $valuel) {
print $value1->content->firstName;
}
但它不打印任何價值。
###從下面的答案全部工作代碼:###
助手文件:
####### --- Get live viwers list for each broadcast --- ########
if (! function_exists('gettviewers'))
{
function gettviewers($broId,$size){
$CI =& get_instance();
$url = API_SERVER.'broadcasts/public/'.$broId.'/top-viewers?size='.$size;
$json = json_decode(file_get_contents($url), true);
return $json;
}
}
在視圖:
$arrayl = gettviewers($post->id, WI_LIVEUSERSIZE);
foreach($arrayl as $value1)
{
print $value1[0][firstName];
}
謝謝@Wolen我打印如下:print $ value1 [0] [firstName]; – gitu