Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.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 多维数组中的搜索值_Php_Arrays_Multidimensional Array - Fatal编程技术网

Php 多维数组中的搜索值

Php 多维数组中的搜索值,php,arrays,multidimensional-array,Php,Arrays,Multidimensional Array,我想在多维数组中查找值。我有这样一个数组: array(4) { [0]=> array(2) { [0]=> string(3) "840" [1]=> string(3) "841" } [1]=> array(1) { [0]=> string(3) "842" } [2]=> array(4) { [0]=> string(3) "333"

我想在多维数组中查找值。我有这样一个数组:

array(4) { 
    [0]=> array(2) { 
        [0]=> string(3) "840" 
        [1]=> string(3) "841" } 
    [1]=> array(1) { 
        [0]=> string(3) "842" } 
    [2]=> array(4) { 
        [0]=> string(3) "333" 
        [1]=> string(3) "723" 
        [2]=> string(3) "749" 
        [3]=> string(3) "750" } 
    [3]=> array(4) { 
        [0]=> string(3) "248" 
        [1]=> string(3) "268" 
        [2]=> string(3) "269" 
        [3]=> string(3) "270"   } 
}
我发现这个函数:

function in_array_r($needle, $haystack, $strict = false) {
    foreach ($haystack as $item) {
        if (($strict ? $item === $needle : $item == $needle) || (is_array($item) && in_array_r($needle, $item, $strict))) {
            return true;
        }
    }

    return false;
}
但这一if声明:

if(!$this->in_array_r($id, $myArray) {} 
不搜索。。。我真的不知道为什么。我做错了什么,伙计们?我已经分析了我的代码多次,它似乎是好的

编辑: 我有这个:

foreach($koszyk as $Id_produkty => $Ilosc) {
   if(!$this->in_array_r($Id_produkty, $myArray)) {
       // If the Id_produkty variable is not in $myArray I want to skip to the next element in $koszyk
       continue;
   }

   // Here is mySql query and I'm retrieving data depends on $Id_produkty
}
但是似乎
in_array\u r
函数在它之后退出了代码。。。它不会为我返回任何值

哇,当我将error_reporting设置为E_ALL时,我得到了一个错误:调用_array_r()中未定义的函数,我必须弄清楚这是为什么

编辑2:
好的,我得到了这个,在调用内部的数组函数之前,我必须添加
$this->

您是否要求在多维数组中使用数组中的函数? 如果是这样,那么这段代码可能就是您要问的,不过您的问题并不清楚

function in_multiarray($elem, $array)
{
    $top = sizeof($array) - 1;
    $bottom = 0;
    while($bottom <= $top)
    {
        if($array[$bottom] == $elem)
            return true;
        else 
            if(is_array($array[$bottom]))
                if(in_multiarray($elem, ($array[$bottom])))
                    return true;

        $bottom++;
    }        
    return false;
}

 if(in_multiarray(840,$arrayValue)){
    echo "value is present in the array";
 }
_multiarray($elem,$array)中的函数 { $top=sizeof($array)-1; $bottom=0;
虽然($bottomOk)我得到了这个,但在调用内部的\u array\r函数之前,我必须添加
$this->
。我已经找到了答案,因为我将error\u reporting设置为E\u ALL,错误是:调用\u array\u r()中未定义的函数

如果我们知道您期望的输出和实际得到的输出,这总是有帮助的。编辑:请添加到问题中,而不是在评论中。请提供更多详细信息。