note 100771 added to book.array
| From: | infoatcurtinsNOSPAMcreationsdotcom at osu1 dot php dot net | Date: | Fri, 05 Nov 2010 15:49:13 +0000 |
| Subject: | note 100771 added to book.array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-173784@lists.php.net to get a copy of this message | ||
Another way to create a multidimensional array that looks a lot cleaner is to use json_decode.
(Note that this probably adds a touch of overhead, but it sure does look nicer.) You can of course
add as many levels and as much formatting as you'd like to the string you then decode.
Don't forget that json requires " around values, not '!! (So, you can't enclose
the json string with " and use ' inside the string.)
As an example:
<?php
$myarray['blah'] = json_decode('[
{"label":"foo","name":"baz"},
{"label":"boop","name":"beep"}
]',true);
print_r($myarray)
?>
returns:
Array
(
[blah] => Array
(
[0] => Array
(
[label] => foo
[name] => baz
)
[1] => Array
(
[label] => boop
[name] => beep
)
)
)
----
Server IP: 69.147.83.197
Probable Submitter: 65.183.150.84
----
Manual Page -- http://www.php.net/manual/en/book.array.php
Edit -- https://master.php.net/note/edit/100771
Del: integrated -- https://master.php.net/note/delete/100771/integrated
Del: useless -- https://master.php.net/note/delete/100771/useless
Del: bad code -- https://master.php.net/note/delete/100771/bad+code
Del: spam -- https://master.php.net/note/delete/100771/spam
Del: non-english -- https://master.php.net/note/delete/100771/non-english
Del: in docs -- https://master.php.net/note/delete/100771/in+docs
Del: other reasons-- https://master.php.net/note/delete/100771
Reject -- https://master.php.net/note/reject/100771
Search -- https://master.php.net/manage/user-notes.php