creating JSON arrays (square brackets)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jimiwa
Forum Newbie
Posts: 3
Joined: Sat Oct 31, 2009 2:42 pm

creating JSON arrays (square brackets)

Post by jimiwa »

I'm trying to do some server/client programming and I already
have figured out how to create php arrays and translate those
arrays into json data. The thing is when using php arrays and
translating them into json data, the php arrays translate into
json objects holding name value pairs (curly bracket syntax {})
and they do not translate into JSON arrays (square brackets [] )
How do I create JSON objects in php that contain JSON arrays,
with square brackets? Any help would be great. Thanks.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: creating JSON arrays (square brackets)

Post by Weirdan »

It's automatically done when your array contains integer, zero-based keys (and you can't have non-integer keys in js arrays anyway).
Post Reply