我的PHP代码中有一个multidimesional数组...
$wayPoints = $_POST['wayPoints'];
print_r ($wayPoints);
返回
[[ “1dcb4f6575fbf5ee4ebd542d5981a588”,7.67468,44.91085],[ “7503c3e97935960d0f7abcb6f7ad70f4”,7.67614,44.90977]]
我需要在数组中获取index = 1和index = 2的值:如果我尝试获取值
7.67468
使用
print_r ($wayPoints[0][1]);
我获得了
Notice: Uninitialized string offset: 1
为错误
使用
print_r ($wayPoints[0]);
我获得了
[
为错误
建议?
答案 0 :(得分:2)
由于您的$_POST['wayPoints']
绝对是json_encod
ed字符串,请尝试以下代码:
// decode your json-string to array
$wayPoints = json_decode($_POST['wayPoints'], true);
// if you want to check what you have:
print_r($wayPoints)
// echo required item:
echo $wayPoints[0][1];
有关json
的更多信息,请参阅此处,文档或谷歌。