The question:
I have this array coming through a POST field
{"name":"sample","email":"[email protected]","comments":"test"}
I want to split it apart and run it through an array, so the end result would be
name sample
email [email protected]
comments test
What I have tried is this:
$a = $_POST['rawRequest'];
$a = json_encode($a);
foreach ($a as $k => $v) {
echo "\$a[$k] => $v <br />";
}
But it doesn't do anything, however when I test it with this variable (over using the POST)
$a = array("name" => 1,"email" => 2,"sample" => 3);
It works as expected.
Trying to understand what is going on
It is obviously because what I am dealing with here is two different types of array. However after endless google'ing I can't find anywhere which explains the difference (of the arrays below basically). So +1 to an explination which makes my relatively newbie mind understand what is happening and why it is wrong
{"name"=>"sample","email"=>"[email protected]"=>"comments":"test"}
{"name":"sample","email":"[email protected]","comments":"test"}
$_POST['rawRequest']? You are callingjson_encode()which doesn't make sense here. What is the value you started with from$_POST?json_decode()it, notjson_encode().