I am currently learning php. I just coded this function and I was hoping for the function to take a name and check if the name is in the multi array. If the name is contained in it, it will give back the name and the salary and job.
I used a foreach to loop through the list. I created the list outside of the function in a global scope. But am getting this error when I run the code. It is saying "multy is undefined". I don't understand why because is defined.
The following message occurs:
Notice: Undefined variable: multy in C:\xampp\htdocs\projects\index.php on line 19
Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\projects\index.php on line 19
Here's my code
<?php
$multy = [
[
'staff' => 'ben', 'job' => 'cooking', 'salary' => 1500,
],
[
'staff' => 'cy', 'job' => 'chef', 'salary' => 2000,
],
[
'staff' => 'sylva', 'job' => 'software engineer', 'salary' => 15000,
],
];
function checkingList($name){
foreach($multy as $mult){
if($mult['staff'] === $name){
echo $mult['staff'] .', You are hired. Your job is ' . $mult['job'].' and your salary is'. $mult['salary'];
}
}
}
checkingList('sylva')
?>