Page 1 of 1

arrays

Posted: Mon Aug 21, 2006 1:11 pm
by Dave2000

Code: Select all

$bakery = array(
"cherry" => array("£100","2 pieces","sugar"),
"apple" => array("£200","3 pieces","sugar"),
"other" => array("£300","1 piece","sugar-free"),
);
The number "300" could be called by the index, $bakery[other][0]

However, is it possible, and if so how...

do i assign a key to the 300 index, so it could be called by something like $bakery[other][cost]

I hope this makes sense.

Shears :)

Posted: Mon Aug 21, 2006 1:14 pm
by Oren
Exactly like you did it with "cherry", "apple" and "other".
Also, get rid of the comma after the last array :wink:

Posted: Mon Aug 21, 2006 2:39 pm
by Dave2000
Thank you. I realised what i did wrong. :oops:

I have another question. It's different but related to the same array so i'll ask here...

Code: Select all

'5' => array('gold' => '50,000,000 gold','Uprade to Level 5','cost' => '50000000')
The seperator/commas in "50,000,000 gold" seem to be confusing the associative array. I tried escaping with a backslash before the commas but that didn't seem to make an difference. Is it possible to leave the commas in?

Thank you :)

Shears

Posted: Mon Aug 21, 2006 2:45 pm
by feyd
They don't confuse the array. :?

Posted: Mon Aug 21, 2006 2:46 pm
by Oren
The commas shouldn't cause any problems, it's probably something else you did wrong.

Posted: Mon Aug 21, 2006 3:03 pm
by Dave2000
Ahh i see what i did wrong. I did not realise that all the keys get shifted down one if there is an "associative style" name of an index before indexes with normal key naming - if that makes sense lol. I thought this affect was caused by the commas. Oh well. Thank you ^^

Shears :)