Please, somebody help me with the" If line" i’m making an exercise the rests of my code work, but the last line with If statment doesn’t How can do this?
`<?php
$employees = array (
array("Name" => " Harry ", "Age" => 25 , "Department" => " Management"),
array("Name" => " Jack ", "Age" => 31, "Department" => " Developer"),
array("Name" => " Harry ", "Age" => 35, "Department" => " Developer")`
);
foreach ($employees as $element){
echo " Empolyers name :" ,$element ['Name'] ,'<br/>' ;
echo " Age :" ,$element['Age'] ,'<br/>' ;
echo " Function :" ,$element ["Department"];
echo "<br>";
}
$element =0;
while ($element <count($employees)){
echo $employees [$element ]["Name"];
echo "<br>";
$element++ ;
echo "<br>";
if ([$element ]["Name"] == "Jack" ) {
echo "He is the senior Developer", $element["Name"] ;
} }
I tried to set condition based on the array name, or only $key but i can’t get the function to react`
2
Answers
if ([$element ]["Name"] == "Jack" )
there is no array just 2 indexes
First of all, you need to have to add
$employees
in the if statement.You change the value of $element, so you get the value of the next array values.
Second, you can use
array_filter
.