[英]How to pass array of array from javascript into php without ajax?
I want to pass a array of array from javascript into php. 我想将一个数组数组从javascript传递到php。 what is the simplest way to do it? 最简单的方法是什么?
Array in javascript likes: javascript中的数组喜欢:
var resultArray = [
{"id":"1", "description":"aaa", "name":"zzz", "titel":"mmm"},
{"id":"2", "description":"bbb", "name":"yyy", "titel":"nnn"},
{"id":"3", "description":"ccc", "name":"xxx", "titel":"lll"},
{"id":"4", "description":"ddd", "name":"www", "titel":"qqq"},
{"id":"5", "description":"eee", "name":"vvv", "titel":"rrr"}
]
windows.location.href = "searchResults.php?resultArray=" + JSON.stringify(resultArray);
in the php I use: 在我使用的PHP中:
$resultArray = json_decode($_GET['resultArray']);
echo $resultArray[0]['id']; // should be "1", but show nothing
Thanks in advance for every reply! 每个回复都要提前感谢!
json_decode
will create objects for objects encoded as JSON. json_decode
将为编码为JSON的对象创建对象。 If you want an associative array instead, pass true
as second argument: 如果您想要一个关联数组,请将true
作为第二个参数传递:
$resultArray = json_decode($_GET['resultArray'], true);
Reference: http://php.net/manual/en/function.json-decode.php 参考: http : //php.net/manual/en/function.json-decode.php
Its json_decode() not json.decode()
$resultArray = json_decode($_GET['resultArray']);
if you print_r($resultArray
) you will get a standard class array and you can access it by echo $resultArray[0]->id
and will give you 1; 如果你print_r($resultArray
)你会得到一个标准的类数组,你可以通过echo $resultArray[0]->id
访问它,它会给你1;
它是json_decode
,而不是json.decode
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.