I have the following function which does some stuff and returns an array:
- function do_work($array){
- $result = array();
-
- array_push($result, array("HAHAHAH" => "looooooool"));
-
- foreach($array as $key=>$val){
- array_push($result, array($key => $val));
- }
-
- return $result;
- }
I originally call this and pass the $_GET
array in it. What I expect at the end is a flat JSON object. But this returns a JSON array instead:
in my calling code:
- $array = do_work($_GET);
- echo json_encode($array);
if I give the function following GET
array:
handler.php?action=register_new_user&shit=happens
This will be the result, but I want it to be a flat JSON not an array:
[{"HAHAHAH":"looooooool"},{"action":"register_new_user"},{"shit":"happens"}]