Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.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 如果数组在数组中,\u array()在数组中?_Php_Arrays - Fatal编程技术网

Php 如果数组在数组中,\u array()在数组中?

Php 如果数组在数组中,\u array()在数组中?,php,arrays,Php,Arrays,第一次尝试在数组中查找对象时,将数组同时用作针和干草堆。因此,两个阵列的示例: 我的动态形成的数组: Array ( [0] => [1] => zpp [2] => enroll ) 我的静态比较数组: Array ( [0] => enroll ) 和我的in_array()if语句: if (in_array($location_split, $this->_acceptable)) { echo 'f

第一次尝试在数组中查找对象时,将数组同时用作针和干草堆。因此,两个阵列的示例:

我的动态形成的数组:

Array ( 
    [0] => 
    [1] => zpp 
    [2] => enroll 
) 
我的静态比较数组:

Array ( 
    [0] => enroll 
) 
和我的
in_array()
if语句:

if (in_array($location_split, $this->_acceptable)) {
   echo 'found';
}
$location_split; // is my dynamic
$this->_acceptable // is my static

但是从这个发现并没有打印出来,就像我期望的那样?我在这里到底失败了什么?

因为数组中没有包含
数组('enroll')
的元素(只有
'enroll'


最好使用
array\u diff()
,如果结果与原始数组相同,则找不到匹配项。

因为数组中没有包含
array('enroll')
的元素(仅
'enroll'


您最好使用
array\u diff()
,如果结果与原始数组相同,则找不到匹配项。

您正在交换\u array中
的参数。必须是,

 if(in_array($this->_acceptable, $location_split))
{
  echo 'found';
 }
编辑:尝试使用
array\u intersect


您正在交换_数组中
的参数。必须是,

 if(in_array($this->_acceptable, $location_split))
{
  echo 'found';
 }
编辑:尝试使用
array\u intersect


如果我理解正确,您希望查看第一个数组的条目是否存在于第二个数组中

您可以查看
array\u intersect
,它将返回一个在您传递的所有数组中都存在的内容数组

$common = array_intersect($this->_acceptable, $location_split);
if (count($common)) {
    echo 'found';
}
如果该数组的计数至少为1,则至少有一个公共元素。如果它等于动态数组的长度,并且数组的值是不同的,那么它们都在其中


当然,数组将能够告诉您哪些值匹配。

如果我理解正确,您希望查看第一个数组的条目是否存在于第二个数组中

您可以查看
array\u intersect
,它将返回一个在您传递的所有数组中都存在的内容数组

$common = array_intersect($this->_acceptable, $location_split);
if (count($common)) {
    echo 'found';
}
如果该数组的计数至少为1,则至少有一个公共元素。如果它等于动态数组的长度,并且数组的值是不同的,那么它们都在其中


当然,数组将能够告诉您哪些值匹配。

以这种方式尝试,这是我自己第一次想到的,但两个方向都是一样的。我自己也是这么想的,但两个方向都是一样的。我想看看动态数组中是否存在任何静态数组值。但是如果有意义的话,不是全部,也不是全部。@chris:然后检查
array\u intersect
返回的数组的计数是否至少为1。添加了一个代码示例。我想看看动态数组中是否存在任何静态数组值。但是如果有意义的话,不是全部,也不是全部。@chris:然后检查
array\u intersect
返回的数组的计数是否至少为1。添加了一个代码示例。