473,385 Members | 1,912 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

PHP-Like associative array initialization ?

Is is possible to initialize a javascript associative array inline, as
you would do in PHP, e.g. :

<?php
$a = array("abc" => "def", "ghi" => "jkl");
?>
Jul 23 '05 #1
2 10232
Remi Bastide wrote:
Is is possible to initialize a javascript associative array inline, as
you would do in PHP, e.g. :

<?php
$a = array("abc" => "def", "ghi" => "jkl");
?>


Oops... forget about "associative arrays", as they sometimes cause
flaming discussion down here. Just call them objects (javascript
objects), and think of them as (imperfect) associative arrays.

As for the initialisation syntax, which is the javascript object
initialisation syntax ( see http://www.json.org ), you should be fine with :

a = { "abc": "def",
"ghi": "jkl" };

The quotes are optionnal, so the following is fine, too:

a= { abc: "def",
ghi: "jkl" }

However, if one of your keys has spaces or weird characters in it, se
the quotes:

cplx = { "abc d": "efg",
hij: "klm" };

Hope this helps,
Alexis
Jul 23 '05 #2
Just what I needed, thanks.
Alexis Nikichine <al**************@somedomain.fr> wrote:
Remi Bastide wrote:
Is is possible to initialize a javascript associative array inline, as
you would do in PHP, e.g. :

<?php
$a = array("abc" => "def", "ghi" => "jkl");
?>


Oops... forget about "associative arrays", as they sometimes cause
flaming discussion down here. Just call them objects (javascript
objects), and think of them as (imperfect) associative arrays.

As for the initialisation syntax, which is the javascript object
initialisation syntax ( see http://www.json.org ), you should be fine with :

a = { "abc": "def",
"ghi": "jkl" };

The quotes are optionnal, so the following is fine, too:

a= { abc: "def",
ghi: "jkl" }

However, if one of your keys has spaces or weird characters in it, se
the quotes:

cplx = { "abc d": "efg",
hij: "klm" };

Hope this helps,
Alexis


Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: lawrence | last post by:
I haven't been able to reach www.php.net for days. Most of the rest of the web is working for me, though I've bad trouble reaching any English sites. Anyone else having trouble?
6
by: the wonderer | last post by:
This is an elementary question, but I've not been able to find the answer, so here goes: I am developing a site using php. I have the html header information in a file that I include in all the...
1
by: jdurden | last post by:
am currently woking on building this site: www.maverick-spirit.com. everything seems to be fine except the press releases page. When you click on one of the press releases in the left column under...
0
by: tsivaraman | last post by:
I am trying to build php-5.2.1 in RedHat Linux 9. I have installed libxml2-2.6.11,mysql-5.0.33,httpd-2.2.4(apache) successfully.When i do 'make' from the php directory,i get the following...
0
by: Yannick | last post by:
Hi, I'm Julien from France, We have recently install a new Web Server for my company The server is composed : - Linux RedHat RHEL4 U4 - Httpd-2.0.52-27.ent - Oracle Database 10.2.0.1
0
by: Benjamin Grieshaber | last post by:
Hi, I´m on SuSE 9.3 with xmlrpc-c and xmlrpc-c-devel installed (ver. 0.9.10) I tried to compile php with xmlrpc support and got the following errors: ...
3
by: jaddi1 | last post by:
Hi, I am trying to make a multi-level drop-down menu similar to what is seen here: http://www.cssplay.co.uk/menus/simple_vertical.html. My problem is that some of the menu will be populated from...
9
by: mekalai82 | last post by:
i have information.php file that file contain following coding <?php echo phpinfo(); ?> while i calling the URL ("http://localhost/information.php"). i am getting the coding <?php echo...
4
by: mechphisto | last post by:
I'm working on a friend's box, Fedora Core 6. It has PHP 5.1.6. I need to install mcrypt into it, and the only way I can find to do it is from source then recompile PHP. So I did all that, and got...
5
Chrisjc
by: Chrisjc | last post by:
Good afternoon, I am seeking some php configuration help. Here is the run down I am running Windows server 2003 and IIS V6.0 I have never had issues before until now. I have Symantec Antivirus 11.0...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.