2

I know that in_array() does not work on multidimensional arrays. I tried to implement this in my code:

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 I always get following message

Fatal error: Uncaught Error: Call to undefined function in_array_r()

There is a code where I need to check does my value exist in array:

class classification {
  foreach ($valueArray as $values => $arrayEV) {
    $valueCode = $arrayEV;
       #NOW I NEED TO CHECK DOES $valueCode EXIST IN ARRAY CALLED '$v'
 ...

But when I add

echo in_array_r("Irix", $v) ? 'found' : 'not found';

I get that fatal error.

5
  • Do you get the fatal error for the missing function in the same file that contains the function, or in another file? Commented Dec 28, 2017 at 13:58
  • In the same file...Function is defined in classification.php, function is called also in classification.php. Error message => <b>Fatal error</b>: Uncaught Error: Call to undefined function in_array_r() in C:\xampp\htdocs\xml\class\classification.php:82 Commented Dec 28, 2017 at 14:02
  • If it is defined inside of the class use $this->in_array_r() instead of just in_array_r(). If it is not please provide the whole class as code to your question. Commented Dec 28, 2017 at 14:11
  • It helped me, thank you. Now problem is that it returns me 'not found' in every case, I hope that I will find solution. Thank you one more time. Commented Dec 28, 2017 at 14:37
  • stackoverflow.com/questions/12583353/… Commented Dec 28, 2017 at 14:40

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.