0

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

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

"iphone notepad" <== I'd say that's the problem then. Nice work btw!
2

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 :-)

4 Comments

Also the ?> at the end is redundant unless you plan to have raw HTML after it.
But why is there an error at line 3, as is reported by OP's link?
It's all part of the same array structure. My guess is that codepad isn't reporting it correctly. Or maybe it's a different version of PHP, I am using 5.4.6.
Well, a whole bunch of PHP versions since 4.3.0 complain about this error and not line 3. So I'm not so sure it's a PHP version problem. Edit: Found the problem, garbage characters.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.