Created
June 14, 2013 22:24
-
-
Save cebe/5785749 to your computer and use it in GitHub Desktop.
This is how json_encode() treats arrays...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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