Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在数组内搜索MYSQL输出上的值_Php_Mysql_Arrays_String - Fatal编程技术网

Php 在数组内搜索MYSQL输出上的值

Php 在数组内搜索MYSQL输出上的值,php,mysql,arrays,string,Php,Mysql,Arrays,String,下面的代码似乎不起作用,或者在数组中找不到任何内容。我正在使用“in_数组”搜索堆栈中的指针。我还尝试过用逗号分隔的方式分解内容,但不起作用。有什么建议吗?我还尝试了“数组搜索” in_array()无法使用这种数组,因为它是多维数组 您的阵列如下所示: $resultarray[0]['domain_name'] = 'first row domain name'; $resultarray[0]['bid'] = 'first row bid'; $resultarray[1]['domai

下面的代码似乎不起作用,或者在数组中找不到任何内容。我正在使用“in_数组”搜索堆栈中的指针。我还尝试过用逗号分隔的方式分解内容,但不起作用。有什么建议吗?我还尝试了“数组搜索”

in_array()
无法使用这种数组,因为它是多维数组

您的阵列如下所示:

$resultarray[0]['domain_name'] = 'first row domain name';
$resultarray[0]['bid'] = 'first row bid';
$resultarray[1]['domain_name'] = 'second row domain name';
...
您不能在数组()中使用
进行搜索,因此必须使用另一种方法,例如在数组上循环,或者以不同的方式构建
$resultarray

类似地,
array\u search()
在多维数组上不起作用,因此您可以执行类似于在第一个维度上循环和
array\u search()
-ing每个第二个维度的操作


如果您需要更多详细信息,请告诉我。

看起来您这里有一个“数组数组”。也就是说,在while()循环中,$row是一个数组,它对应于mysql查询中的数据。因此,$resultarray的每个元素实际上都包含一个数组,而不是一个字符串

尝试这样做:
print\r($resultarray)
。这将显示$resultarray的整个结构,您可以看到如何创建数组数组


要在数组中使用,您需要执行类似于在数组中的
(“test”,$resultarray[0])

的操作。我相信您遇到的问题是,它在数组中只搜索二维数组的第一维。我也不明白为什么在搜索之前要将整个结果加载到数组中(但这在程序的其他地方可能有用)

尝试:


打印、变量和转储是你的朋友。理解你的数据比一个接一个地尝试所有不同的php函数要快。嘿,我可以有更多的细节吗?我也认为这将是这个问题的解决方案。
$resultarray[0]['domain_name'] = 'first row domain name';
$resultarray[0]['bid'] = 'first row bid';
$resultarray[1]['domain_name'] = 'second row domain name';
...
$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))
{
  if (in_array("test",$row))
  {
     echo "Match found";
  }
  else
  {
     echo "Match not found";
  }
}
 $found = false;
 while($row = mysql_fetch_array($result4))
 {
    if (in_array($needle, $row){
      print "here it is";
      $found = true;
      break;
 }

 if (!$found) {
      print "not found";
 }