I'm trying to get whether name exists in my array that I have acquired from my database table. The array contains the whole name field of the table members
However,on using in_array()
function, the result for any search is always false
Here is how the array looks like
Array ( [0] => Array ( [name] => Jane )
[1] => Array ( [name] => Kelvin )
[2] => Array ( [name] => James )
[3] => Array ( [name] => Leon )
[4] => Array ( [name] => Steve )
[5] => Array ( [name] => Jenifer )
)
And here is my php code to check if a name exists
<?php
require_once 'databaseconn.php';
#To get connection
$mysqli = new mysqli($db_hostname, $db_username, $db_password,$db_database);
#To get array of names from my database
$stmt = $mysqli-> prepare('SELECT name FROM members WHERE id');
$stmt->execute();
$result = $stmt->get_result();
#To store result as array in variable $application_names
while ($row = $result->fetch_assoc()) {
$member_names[] = $row;
}
#To test if name exists
$name = "Jane";
if (in_array($name, $member_names))
{
echo "Match found";
}
else
{
echo "Match not found";
}
?>