-4
如何循環瀏覽PHP中的json_decode($ json_emp)輸出並獲取值?如何在PHP中循環訪問這些值
$array_emp = json_decode($json_emp);
var_dump($array_emp)
{"info":[{"id":"10","name":"employee1"},{"id":"11","name":"employee2"},{"id":"12","name":"emplyee3"}]}
需要找到獲取ID和名稱的個人值。這是數組。
$array_emp = json_decode($json_emp,true);
Array
(
[info] => Array
(
[0] => Array
(
[id] => 10
[name] => employee1
)
[1] => Array
(
[id] => 11
[name] => employee2
)
[2] => Array
(
[id] => 12
[name] => emplyee3
)
)
)
這裏是對象;
stdClass Object
(
[info] => Array
(
[0] => stdClass Object
(
[id] => 10
[name] => employee1
)
[1] => stdClass Object
(
[id] => 11
[name] => employee2
)
[2] => stdClass Object
(
[id] => 12
[name] => emplyee3
)
)
)
請讓我知道如何遍歷這些並獲得值。試了很多,感到困惑。
http://php.net/manual/en/control-structures.foreach.php – Streetlamp
而另:http://stackoverflow.com/q/15607029/1065197 –