在php中发出解码ajax帖子的问题

问题描述:

I am trying to decode an array of objects that I made in javascript and sent to php however, I cant seem to decode it correctly. The array with an object looks like this: enter image description here

the php code that I am using to get the information is this:

$allInformation = $_POST['information'];

//this works
$user = $allInformation[count($allInformation)-2];
$num = $allInformation = [count($allInformation)-1];
//this doesnt work 
$array = var_dump(json_decode($allInformation));

The index of array 1 and 2 work just fine, however, I cant seem to decode index 0 which is the object. How may I go about this?

我正在尝试解码我​​在javascript中制作并发送到php的对象数组但是,我似乎无法 正确解码。 带有对象的数组如下所示: p>

我用来获取信息的PHP代码是这样的: p >

  $ allInformation = $ _POST ['information']; 
 
 //这工作
 $ user = $ allInformation [count($ allInformation)-2]; 
 $  num = $ allInformation = [count($ allInformation)-1]; 
 //这不起作用
 $ array = var_dump(json_decode($ allInformation)); 
  code>  pre> 
 
  

数组1和2的索引工作正常,但是,我似乎无法解码作为对象的索引0。 我怎么能这样做? p> div>

got it to work, the array to php which was JSON stringified was [{"user":"user","date":"03/17/2017"},"user",134997] and i did $update = json_decode($_POST['information']); and then looped it to get user and date as obejcts i.e. $update[$i]->date . thanks all