Testing the "Array Index"


Begin PHP output

Month 5 is May
Month Aug is August
Month June is June


END PHP output

<?

$MonthName = array(
1 =>"January","February","March","April","May","June","July","August","September",
"October","November","December",

"Jan"=>"January","Feb"=>"February","Mar"=>"March","Apr"=>"April","May"=>"May",
"Jun"=>"June","Jul"=>"July","Aug"=>"August","Sep"=>"September","Oct"=>"October",
"Nov"=>"November","Dec"=>"December",

"January"=>"January","February"=>"February","March"=>"March","April"=>"April","May"=>"May",
"June"=>"June","July"=>"July","August"=>"August","September"=>"September","October"=>"October",
"November"=>"November","December"=>"December"
);

print("Month 5 is " . $MonthName[5] . "<br>\n");
print("Month Aug is " . $MonthName["Aug"] . "<br>\n");
print("Month June is " . $MonthName["June"] . "<br>\n");
     }

     
?>

In the code above we create a multidimensional array, then search through it, printing out each value for which the appropriate key is requested.

Back to Bill's PHP