3 ms·
It's kind of JSON-wish, so this would make more sense: $bar = [1, 2, 3]; $foo = { 'bar': TRUE, 'baz': 'socks' };
by rorrr 15y ago
It's kind of JSON-wish, so this would make more sense:
$bar = [1, 2, 3];
$foo = {
'bar': TRUE,
'baz': 'socks'
};
- ars 15y agoWhat would be your syntax when you mix them? Which is perfectly legal to do: array(1, 'bar' => TRUE, 3, 'baz' => 'socks'); But I do like this syntax idea.
- nir 15y agoIIRC in PHP every array is internally a hash (ie "associative array"), so $bar is {0:1, 1:2, 2:3} in any case?
- z92 15y agoFor being JSONish it should be $foo = { bar: TRUE, baz: 'socks' }; where keys are unquoted. The less typing the better.
- swivelmaster 15y agoHowever, PHP allows me to do this: $keyName = "bar"; $array = array($keyName => "baz"); So in that instance it makes sense to force people to quote their keys. Also, bar or baz could be constants.
- rorrr 15y agoThat's against the spec. json_decode() will not even decode this. http://www.json.org/ http://www.json.org/ I know some browsers allow it, but it's not true JSON.
- Todd 15y agoThis is more perlish, with the exception of the map delimiter. If you proposed => it would be identical to perl.
- phaylon 15y agoAlmost, but Perl's => also auto-quotes barewords (and only barewords) on the left hand side, so foo => 23 is identical to "foo" => 23.