从生成的数组中提取信息(PHP)
从生成的数组中提取信息(PHP),php,arrays,Php,Arrays,createTour()函数生成一个虚拟巡更ID。 通过在函数中包括print\r($buffer)或var\u dump($buffer),我可以看到生成的id 以下是生成的阵列的外观: array(1) { [0]=> string(344) "{"type":"TOUR_CREATED","details":{"class":"models.pano.VirtualTour","created":1582643053000,"modified":1582643053800,"id":
createTour()
函数生成一个虚拟巡更ID。
通过在函数中包括print\r($buffer)
或var\u dump($buffer)
,我可以看到生成的id
以下是生成的阵列的外观:
array(1) { [0]=> string(344) "{"type":"TOUR_CREATED","details":{"class":"models.pano.VirtualTour","created":1582643053000,"modified":1582643053800,"id":"5e55376dff02e155e6732614","itemID":"5e55376dff02e155e6732615","userID":"58e4c9d15f6266268511ac5d","agentID":"58e4c9d15f6266268511ac5e","name":"pasda","panoramas":[],"limitedAccess":false,"grantAccessAutomatically":false}}" }
array(1) { [0]=> string(29) "{"type":"TOUR_ALREADY_EXIST"}" }
我想做的是提取这些信息并将其包含在createRoomAndPano()
函数中,确切地说{here}curl\u setopt($ch\u 1,CURLOPT\u URL,“https://app.immoviewer.com/rest/v1/tour/{here}/pano”)代码>
问题是:如何从PHP中生成的数组中提取id
中包含的信息?从您发布的内容中,$buffer是一个JSON字符串数组。
做一个`
$foo = json_decode($buffer[0], true);
将返回一个关联数组,可以使用该数组提取ID,如
$id = $foo['details]['id'];
然后设定它
curl_setopt($ch_1, CURLOPT_URL, 'https://app.immoviewer.com/rest/v1/tour/'.$id.'/pano');
您首先要意识到这里有字符串形式的JSON,因此首先需要对其进行解码。在那之后,这可以归结为嵌套数据结构中非常简单的导航。@Africomm我所做的就是格式化这个家伙的答案,使其更可读,然后发布一个链接,这样他就可以自己查看文档了。