I am trying to get the following output that will produce the following json
[{"description":"name","errorcode":777},{"description":"Department","errorcode":"yyy"}]
PHP
if(empty($name)){
$errordesc[] = array('description' => 'name','errorcode' => 777);
}
else if(empty($email)){
$errordesc[] = array('description' => 'Department','errorcode' => "yyy");
}
when I do
echo json_encode($errordesc);
it gives output as
[{"description":"name","errorcode":-2}]
The problem is in the php array.Should I use array_push? Please advice.Thanks in advance.
$array[] = x
is the same asarray_push($array, x)
.-2
coming from? Maybe there's some other code that's overwriting this?