Review of arrays


#1

I don't understand, this code should work

<?php
$fruits = array('bananas', 'apples', 'pears');
echo 'I love eating ' . $fruits[1] . ' too!';
?>

On the screen it echoes the sentence but it says: Oops, try again.
Did you remember to use $fruits[1] in your code? Check the Hint if you need help!


#2

@trumanb,

Have you tried a reset Browser...

++++ reset of session *****************
under certain circumstances you can shoot your Browser in an
inconsistent state.

Therefor it is of an advantage to know that you have 2 reset facilities:

One is the use of the F5-key which does a refresh Browser

and

Two, select&copy your code
Then use the Reset Code button of the course-window,
then paste your code back in.

Addendum
General Notes:
Always refresh the browser after making corrections:
CTRL f5 ( if on Windows or Linux)
CMD r ( if on a MAC).


#3

I did that and that didn't work. What worked it that in echo statement I deleted all but $fruits[1]
And the code was accepted. It makes no sense to me.


#4

I tried your exact code (which is correct) and passed. Not sure what the issue may be. Did you try Leon's advice?

I also tried it with double quotes and embedded variable,

        echo "I love eating $fruits[1] too!";

which also passed.


#5

Check my message above...
Sometimes codeacademy jams...


#6

Did you get it to eventually work, at least?


#7

Yes, even it didn't make sense to me. I finished the whole course today.:sunglasses:


#8

It covers quite a lot of ground, even as an introduction. However, just like the jQuery track, it only scratches the surface. We definitely need to follow up on our studies. If you can find a decent sandbox (phpfiddle comes to mind) to work in, take lots of time to read up on the documentation and get lots of practice.

PHP is mainly for generating documents from templates and data from a database. We need a server to run it on (unless you make your own computer into a server, which is not advisable if you are just beginning). The finished document (the response) is a plain text HTML file that gets sent down to the client.


#9

Thank you. I don't know what a sandbox is. If you'd like to explain more to me it's welcome. I'm looking now at phpfiddle page.


#10

It's a safe place to fiddle with code that won't have any disasterous effects. Playing with PHP on a live website can be very challenging since it does not have any tolerance for syntax errors. It just shuts down and responds with a blank page. If you cannot find the error, the page stays broken. Learn early on the importance of backing up everything before beginning to make changes. At least that way you have a fall back to restore.