2017-05-26 68 views
0

我已經試過了這裏的一堆答案,並且認爲這應該非常簡單..試圖進入一個woo PDF導出插件與ACF集成的鉤子。 。PHP從這種類型的數組中獲取具體項目

如果我運行這一點 -

echo $this->order 

我得到這個 -

{"id":7,"parent_id":0,"status":"processing","currency":"GBP","vers 

我如何拔出只是ID又名第一個項目?

非常感謝!

SOLUTION:

按照以下基本,我用代碼的工作原理是..

$thisOrd = $this->order; 
$obj = json_decode($thisOrd); 
echo $obj->id; 

感謝所有。

+0

這是一個JSON字符串_Well的one_一部分於是擡頭['json_decode()'](http://php.net/manual/en/function.json-decode.php)在手冊 – RiggsFolly

回答

1

你可以嘗試將JSON字符串解碼成stdObject

$obj = json_decode($this->order); 
echo $obj->id; // 7 
+1

是啊....多數民衆贊成在做的方式 – RiggsFolly

+0

完美,謝謝! –

0
$order = json_decode($this->order, true); 
echo $order['id'] 
+1

爲什麼要將完美的物體轉換爲數組? – RiggsFolly

+0

就像他喜歡的那樣,他可以使用json_decode($ this-> order),結果將是stdClass或json_decode($ this-> order,true)的一個實例,結果將是一個數組 –

0

其轉換爲陣列的第一

$arr = json_decode($this->order,true); 
var_dump($arr['id'])