I need to convert a PHP array to json but I don\'t get what I expect. I want it to be an object that i can navigate easily with numeric index. Here\'s an example code:
To get array with objects you can create stdClass() instead of array for inner items like below;
ip = "192.168.0.1"; $itemObject->port = 2016; array_push($json, $itemObject); $json = json_encode($json, JSON_PRETTY_PRINT); echo $json; ?>
A working example http://ideone.com/1QUOm6