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";
}
?>
Associative Array in php
Moderator: General Moderators
Re: Associative Array in php
The error message would have clearly told you that the error was on
that line. Do you see anything wrong with it?
And there are multiple mistakes with the construction of the array.
Code: Select all
foreach($year as $x => &x_value){And there are multiple mistakes with the construction of the array.
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Associative Array in php
It helps to post the error message. Often the error message will tell you exactly what and where the error is.
(#10850)
Re: Associative Array in php
Thank Christopher is running as expected now