how to find an element in multidimensional array
i have the following query:
$simplequery = array('type'=>'/travel/travel_destination',
'id'=>$_POST["hcity"],
'name' => null,
'tourist_attractions' => array(
array('/common/topic/article'=>array(array('guid'=>null)),
'/common/topic/image'=>array(array('guid'=>null))
)
)
);
$queryarray = array('q1' => array('query' => $simplequery));
$jsonquerystr = json_encode($queryarray);
//echo $jsonquerystr;
#run the query
$apiendpoint = "http://www.freebase.com/api/service/mqlread?queries";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "$apiendpoint=$jsonquerystr");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTR开发者_JS百科ANSFER, 1);
$jsonresultstr = curl_exec($ch);
curl_close($ch);
$temp = str_replace("#", "", $jsonresultstr);
$resultarray = json_decode($temp, true);
I want to take the guid string of the '/common/topic/image' array. It is a multidimensional array and i can't find out how to do it. I tried writting
$result = $resultarray["q1"]["result"]["tourist_atractions"]['/common/topic/image'];
but it is not working. can you please help me? thanks
$result = $resultarray["q1"]["result"]["tourist_attractions"]['/common/topic/image'][0]['guid'];
First guess? You misspelt "attractions":
$resultarray["q1"]["result"]["tourist_attractions"]['/common/topic/image'];
精彩评论