473,757 Members | 2,081 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 10248
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 "associativ e 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.f r> 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 "associativ e 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
initialisati on 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
4049
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
38339
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 pages using the require_once function. That is, each page includes the line <?require_once('PageStart.php')?>
1
2056
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 the menu, nothing comes up. I copied the code for the page directly from the press releases page on our main site: www.maverickentertainment.cc, and it is using an identical database, so I am unsure what is wrong. The issue happens when you...
0
1675
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 errors..Not able to proceed further.(./configure went smooth). I request you to provide suggestions to solve this problem. -5.2.1/include -I/lamp/php-5.2.1/main -I/lamp/php-5.2.1 -I/usr/local/ include/libxml2 -I/lamp/php-5.2.1/ext/date/lib...
0
4790
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
2751
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: ext/xmlrpc/.libs/xmlrpc-epi-php.o(.text+0x359): In function `set_zval_xmlrpc_type': /php-5.2.5/ext/xmlrpc/xmlrpc-epi-php.c:1313: undefined reference to `XMLRPC_CreateValueDateTime_ISO8601'
3
4611
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 a database. My menu will be structured as follows: The first setion of the menu is hard-coded (the home and management sections). The rest of the menu will be populated from a database. The top level links (categories) will come from one table...
9
2049
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 phpinfo(); ?> not show the php information...... i am new to the php can you help me?
4
4384
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 the latest PHP, 5.2.5. The ./configure finally went through OK. Make and make install. Then I restarted Apache... but the phpinfo() shows no change. It's still using 5.1.6. When I run "php -v" from command line I get a huge error I'll include...
5
4646
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 Manager, it controls all the Symantec clients in the company. Now it uses a web interface for all of its commands and settings which is called (SEPM) This reporting unit uses php, Symantec by default is loading its php.ini from “C:\Program...
0
10069
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9884
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9735
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8736
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7285
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6556
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5324
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3395
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2697
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.