I have this Variable :
$value = '"item_id"=>"null","parent_id"=>"none","depth"=>0,"left"=>"1","right"=>18';
And I want get item_id and other element from top Variable with Array method, so i write this :
$value_arr = array($value);
$item_id = $value_arr["item_id"];
but i get error Notice: Undefined index: item_id in file.php on line 115
but When i use this method i get fine result successfully :
$value_arr = array("item_id"=>"null","parent_id"=>"none","depth"=>0,"left"=>"1","right"=>18);
$item_id = $value_arr["item_id"];
How i can solve this problem ?
Note: i don't want use 2'nd method because my Variables is Dynamic
UPDATE:
Vincent answered that i must use json_decode and i want to ask another question for better way because my original string that i have is :
[
{"item_id":null,"parent_id":"none","depth":0,"left":"1","right":18},
{"item_id":"1","parent_id":null,"depth":1,"left":2,"right":7},
{"item_id":"3","parent_id":null,"depth":1,"left":2,"right":7}
]
With this information whats the better way for get item_id
, parent_id
and ... ?