Hello,
I am getting this warning Warning: Undefined array key when using the below code. This does return the correct value but I would like to fix the warning. The error says it is on the return line.
You’d need to show us where getLocationMap() is called, and what it’s passing as the $locationId parameter. But clearly the parameter it’s passing is not one of the strings you’ve encoded in the array.
The location id I put just above the method is what is being passed. I actually get back a value of 16 which is correct. But I am still getting the warning.
What is in $locationId when you display it inside the function for debugging purposes?
I make a habit of not using variable names that are the same as parameter names, where I can, to remove any kind of confusion. Seeing that you use it as the variable name in your calling code, and the parameter name inside your function, just adds a little potential for confusion to the casual viewer, even if the compiler isn’t confused.
What you have shown is not calling the function so there shouldn’t be an error in the function. I guess we would all like to see how you are calling the function… Something like this with a value key inside the call?
echo getLocationMap('47V9D0K01JHXW');
How are you testing this function if you are not calling it?