Ahmed Alrawashdeh
Ahmed Alrawashdeh

Reputation: 21

Declaring Multi dimensional arrays | array() as language construct

Why wont this work?

http://codepad.org/5Eic7Pq0

Trying to learn php.

Posted from iphone notepad => codepad.


EDIT:

http://codepad.org/DOIAYMb7

Updates: • removed spaces • replaced html line breaks w/ \n's as per codepad • added code to recognize new makes • seperated makes & models--it looks better

Next step is to implement a table.

Sorry for not posting code directly friends

Upvotes: 0

Views: 56

Answers (2)

nickb
nickb

Reputation: 59699

In your raw code, you have garbage characters that are messing up PHP's parse of the code:

<?php
$cars = array(
   array(
   "make" => "toyota",
   "model" => "corolla",
   "size" => "compact"
   ),

I just downloaded your raw code from the paste, and opened it with a simple text editor. Somebody else can feel free to open it with a more advanced editor to say what garbage characters are actually there but not being displayed in the codepad output. But this is why codepad is reporting an error on line 3.

Upvotes: 3

leftclickben
leftclickben

Reputation: 4614

The error is that you have = in some places where you need =>. Lines 34 and 35

"make" = "nissan",
"model" = "maxima",

Should be like:

"make" => "nissan",
"model" => "maxima",

This is the real message that I got:

PHP Parse error:  syntax error, unexpected '=', expecting ')' in php shell code on line 33

Also, when you're referring to string indexes, you need to use quotes to identify a string literal, so this:

$cars[$i][make]

Should be this:

$cars[$i]['make']

This is only a warning, but it is a good one to avoid :-)

Upvotes: 2

Related Questions