Topic: Associative Array Tutorial Help

Hi,

I am following along, and doing well for the most part until I hit the Array tutorial #2.

Here is what I have, and I blows an error on line 17 everytime. I am getting kind of frustrated because it looks right, yet, it must not be.

What am I doing wrong. It is in the "first line of the actual array.

<?php
//Associative Arrays


$prices_array = array("TV" => "250.00", "DVD" => "100.00", "VHS" => "2.00",);
print $prices_array ['TV'];

?>

Thank you,

Lynn

Last edited by LynnStrauch (July 5, 2009 6:24 am)

Vote up Vote down

Re: Associative Array Tutorial Help

the code snippet works perfectly for me.
is there more code?

My signature goes here --> X

Vote up Vote down

Re: Associative Array Tutorial Help

I get a parse error:
Parse error: parse error in C:\wamp\www\php_work\AssociativeArray.php on line 19


This is what I have for the complete code:

<html>
<head>
<title>Associative Arrays</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF" text="#000000">

<?php
//Associative Arrays

$my_array = array("Elizabeth","Lynn","Lynette",7);
print "The value held in position 2: ";
print $my_array [2];

// Associatative Array Uses Name Value Pairs
print "<br><br>"

$prices_array = array("TV" => "250.00", "DVD" => "100.00", "VHS" => "2.00", );
print $prices_array ['TV'];

?>

</body>
</html>

No matter what I do, it will not work on my computer. I am not sure why this is.

Last edited by LynnStrauch (July 5, 2009 10:40 am)

Vote up Vote down

Re: Associative Array Tutorial Help

Hmm, it sems the array is a bit wrong;

$prices_array = array("TV" => "250.00", "DVD" => "100.00", "VHS" => "2.00", );

Should be (notice the last ", " i removed):

$prices_array = array("TV" => "250.00", "DVD" => "100.00", "VHS" => "2.00");

//Emil Fresk
Sweden

Vote up Vote down

Re: Associative Array Tutorial Help

Well, that did not work either. I am still getting the error after removing the comma and space. Stephan has it working with the comma and space...room for another I am assuming, and it works for him, and it is working for the other guy...but not for me...sigh.

Same Error though:
Parse error: parse error in C:\wamp\www\php_work\AssociativeArray.php on line 19

Lynn

Last edited by LynnStrauch (July 6, 2009 8:03 am)

Vote up Vote down

Re: Associative Array Tutorial Help

Add the line ending semi-colon on the line above the array declaration.

// Associatative Array Uses Name Value Pairs
print "<br><br>";
My signature goes here --> X

Vote up Vote down

Re: Associative Array Tutorial Help

That worked!!!

Thank you! These tutorials are awesome, and so is this board!

Thanks to everyone, especially Stephan.

Lynn Strauch

Vote up Vote down