下面的代码似乎不起作用或在数组上找不到任何内容。我正在使用“in_array”来搜索堆栈中的针。我还尝试用逗号分隔来分解内容,但不起作用。有什么建议么?我还尝试了“array_search”。
$q4 = "SELECT domain_name,slots_config.bid FROM slots_pid,slots_config,slots_sites
WHERE slots_config.bid=slots_pid.bid && slots_sites.aid=slots_pid.aid";
$result4 = mysql_query($q4);
while($row = mysql_fetch_array($result4))
{
$resultarray[] = $row;
}
if (in_array("test",$resultarray))
{
echo "Match found";
}
else
{
echo "Match not found";
}
最佳答案
看起来你这里有一个“数组的数组”。也就是说,在 while() 循环中,$row 是一个数组,对应于 mysql 查询中的数据。所以 $resultarray 的每个元素实际上包含一个数组,而不是一个字符串。
尝试这样做:print_r($resultarray)
。这将显示 $resultarray 的整个结构,您可以看到如何创建数组的数组。
要使用 in_array,您需要执行类似于 in_array("test", $resultarray[0])
关于php - 在数组内搜索 MYSQL 输出上的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/823108/