First of all, sorry for the title, but I didn't know what to put exactly to describe the issue.
Back to the problem, this is what I want to get:
{"0":{"dep":"DIR","user":"10000008","seen":"0000-00-00 00:00:00"},"1":{"dep":"TES","user":"10000008","seen":"0000-00-00 00:00:00"}}
and this is the actual code I am using (that receives data from an input element as array) example:
<input type="text" name="dep[]" />
<input type="text" name="user[]" />
This is the main code I need to "fix":
$user = ($_POST['cc_user']);
$dep = ($_POST['cc_dep']);
$cc = array();
for($i=0;$i<count($_POST['cc_dep']);$i++) {
$cc = array();
$cc['user'] = $user[$i];
$cc['dep'] = $dep[$i];
$cc['seen'] = '0000-00-00 00:00:00';
$x = strval($i);
$cc2["$x"] = $cc;
unset($cc);
}
echo json_encode($cc2);
At the moment, this is the result instead of the one I want to get:
[{"user":"10000008","dep":"DIR","seen":"0000-00-00 00:00:00"},{"user":"10000001","dep":"admin","seen":"0000-00-00 00:00:00"}]
As you can see, the key of the array is not visible, and I need that for an integration on my website.
I tried to specify the $i using:
(string)$istringval($i)"$i"
but I didn't manage to solve the problem. Can someone help, even if it is something really easy?
Thanks in advance!
$_POSTwith parenthesis?$cc2[] = $ccat the end of your loop?$cc2variable and only used in loop. So without declaring variable will not give an effect :)echo json_encode($cc2);?