I want to find values in multidimensional array. I have an array like this:
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" }
}
I have found here this function:
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;
}
But this if statement:
if(!$this->in_array_r($id, $myArray) {}
doesn't search... I really don't know why. What I am doing wrong guys? I have analised my code multiple times and it seems to be ok.
EDIT: I have this:
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
}
But it seems like the in_array_r
function exits the code after it... It doesn't return any value for me.
Wow, when I set error_reporting to E_ALL I got this error: Call to undefined function in_array_r() I have to figure it out why is that
EDIT2:
Ok I got this, I had to add $this->
before calling in_array_r function inside.