So i am trying to search an array and it always gives me false for some reason even tho the letter exists in the name array. This is what i want it to do , search the array, if a match exist it should add the name to the $data array and send it to the AJAX by encode it to JSON. But my IF always gives false
Edit: The answer in the other question did not solve this since that will always cause my array to return false
$user = array(
0 => array(
"id"=> 0,
"photo"=>"smily",
"name"=>"Name One",
),
1 => array(
"id"=> 0,
"photo"=>"smily",
"name"=>"Name Five",
),
2 => array(
"id"=> 0,
"photo"=>"smily",
"name"=>"Name Four",
),
3 => array(
"id"=> 0,
"photo"=>"smily",
"name"=>"Name Three",
),
);
$wordToSearch = "N";
$data = Array();
for($i = 0; $i < count($user); $i++)
{
if(array_search($wordToSearch, array_column($user, 'name')) == false)
{
array_push($data, array(
'name' => $user[$i]['name'],
'img' => $user[$i]['photo'],
'pos' => $user[$i]['position'],
'Id' => $user[$i]['id']
)
);
echo json_encode($data);
}
}