If I do not use MySQL, the PHP in_array function works as expected. In this example, the if statement would execute and display the array contains the keyword blue because the in_array function is able to find keyword blue in the array.
<?php
$keyword = "blue";
$array = array("red", "green", "blue", "yellow");
if (in_array($keyword, $array)) {echo "the array contains keyword $keyword";}
else {echo "the array does not contain keyword $keyword";}
?>
in_array fails to do the same when selecting red, green, blue, yellow from MySQL. In this example, if I echo $array, red green blue yellow is displayed in the Web browser, so I know blue is in the $array variable. However, the else statement executes and displays the array does not contain keyword blue.
<?php
$keyword = "blue";
$con = new mysqli('domain','username','password','database');
$sql = "select * from colors";
$sql_query = $con->query($sql);
while ($row = mysqli_fetch_array($sql_query)) {
$array = $row['colors'];
if (in_array($keyword, $array)) {echo "the array contains keyword $keyword";}
else {echo "the array does not contain keyword $keyword";}
}
?>
If anyone has any tips or suggestions here, I certainly would appreciate it.