Skip to content

Instantly share code, notes, and snippets.

@cebe
Created June 14, 2013 22:24
Show Gist options
  • Save cebe/5785749 to your computer and use it in GitHub Desktop.
Save cebe/5785749 to your computer and use it in GitHub Desktop.
This is how json_encode() treats arrays...
<?php
$a = new StdClass();
$a->prop = 2;
$a->str = "hallo";
$a->arr = array(1,2,3);
echo json_encode($a); // {"prop":2,"str":"hallo","arr":[1,2,3]}
echo json_encode((array)$a); // {"prop":2,"str":"hallo","arr":[1,2,3]}
echo json_encode(array(1,2,3)); // [1,2,3]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment