Fastest way to implode an associative array with keys
If you're not concerned about the exact formatting however you do want something simple but without the line breaks of print_r
you can also use json_encode($value)
for a quick and simple formatted output. (note it works well on other data types too)
$str = json_encode($arr);
//output...
[{"id":"123","name":"Ice"},{"id":"234","name":"Cake"},{"id":"345","name":"Pie"}]
You can use http_build_query()
to do that.
Generates a URL-encoded query string from the associative (or indexed) array provided.