I'm new to php programming, so sorry for any errors whatsoever.
I have a $monthsKeys variable that contains an array going from 0 to 12. I have another array ($Months) that contains 12 months from December to January.
I'm trying to create a function that takes the array as parameter and gets the key value from $monthsKeys so that it can return the month's name contained in $Months.
function getnomMois($monthsKeys){
$monthName= array(['Decembre','Novembre','Octobre','Septembre','Aout','Juillet','Juin','Mai','Avril','Mars','Fevrier','Janvier']);
foreach($monthsKeys as $monthName){
$monthName[] = $monthKeys['numMois'];
}
}
What I expect the function to return:
Instead of 12 for the month's number it returns December
What I'm trying to do:
I try to get the key from the $monthsKeys array and use it to get the value from the $MonthName array
What I understand I need to do:
I must extract the key value from the 1rst array and use it to get the value of the 2nd array accordin to the 1rst array key.
ie: monthKey[12] shoudl allow me to return monthName[12]='December'.
array([syntax.$monthNameon the second line is array, but on the 4th line you change it tostring(when you loop over the values), and then you are trying to do array operation ([]) on that string.$monthNamearray by numbered index; i.e$monthName[0], it will already do what you what it to do.$monthName[0] = 'Decembre'print_r($monthName);right after you declare it and look at the array structure carefully 2) You always want to make sure you don't overwrite your variables, means you don't want to use$monthNamein your foreach loop if you already used it before to define the array with the months name 3) Take a simple approach and start by writing down in pseudo code what exactly you try to do and then start to write the real code