Associative Array in php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nokuthula
Forum Newbie
Posts: 17
Joined: Mon May 02, 2016 10:14 am

Associative Array in php

Post by nokuthula »

Hello

am required to use associative array that will print out the year of registration of each module as well as the module code or name
am getting an error syntax error

<?php
// put your code here
//displaying each modules with years
$year=array("Eup1501"=>"2010","Ict1541"=>"2010","Ict1513"=>"2011",
"Ict1514"=>"2012","Ict1512"=>"2012","Ict1521"=>"2012","Ict1531"=>"2012",
"Ict1532"=>"2013","Fac1501","2015","Ict2611"=>"2014","Ict2621","2014",
"Ict2613"=>"2016","Ict2642","2016");

foreach($year as $x => &x_value){
echo "Key=" .$x . ",Value=" .$x_value;
echo "<br";
}

?>
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Associative Array in php

Post by requinix »

The error message would have clearly told you that the error was on

Code: Select all

foreach($year as $x => &x_value){
that line. Do you see anything wrong with it?

And there are multiple mistakes with the construction of the array.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Associative Array in php

Post by Christopher »

It helps to post the error message. Often the error message will tell you exactly what and where the error is.
(#10850)
nokuthula
Forum Newbie
Posts: 17
Joined: Mon May 02, 2016 10:14 am

Re: Associative Array in php

Post by nokuthula »

Thank Christopher is running as expected now
Post Reply