【发布时间】:2018-07-17 02:18:05
【问题描述】:
我需要一些关于下面关联数组的指南,我如何访问或检索指定的值,例如 JSON 格式的 student_details 中的 student_name "Kevin" 下的高度。
<?php
$college=[
'college_id' => '123',
'student_details'=> [
'student_name'=>[
'Kevin'=> [
'height'=>'170',
'weight'=>'65',
],
'Daniel'=> [
'height'=>'170',
'weight'=>'65',
] ,
'Paul'=> [
'height'=>'179',
'weight'=>'70',
]
]
]
];
echo json_encode($college);
?>
【问题讨论】:
-
你为什么要尝试在 PHP 中处理 JSON?您应该只操作数组并转换为 JSON 以进行输出。
-
如果我需要将这个数组以 JSON 编码传递到另一个页面,我应该如何访问其中的值?
-
另一个页面是 PHP 还是 JavaScript?如果是 PHP 那么你可以使用
json_decode() -
PHP,在我使用json解码后,我应该如何访问我上面提到的指定数据,例如student_details中student_name“Kevin”下的高度
-
在下面查看我的答案
标签: php arrays json associative-array