Hi everyone,

When I look at my $array using

<?php print_r($array) ?>

Here is what I get.

Array
(
[XYZ] => Array
(
[0] => ABC123ABC

        [1] => DEF456DEF

    )

)

I want to be able to detect if 456 exists in the $array and if so

<? echo "456 exists in this array"; ?>

I am new to arrays though and cant seem to get it to work using

<?php

if (in_array(array("*456*"), $array)) {
    echo "456 exists in this array";
}
?>

What am I doing wrong here? Any help is greatly appreciated..

thx

    here is a start, you will have to add a regular expression for the match

    <?php
    function recursive_array_search($needle,$haystack) {
        foreach($haystack as $key=>$value) {
            $current_key=$key;
            if($needle===$value OR (is_array($value) && recursive_array_search($needle,$value) !== false)) {
                return $current_key;
            }
        }
        return false;
    }
    ?>
    

      Thanks alot for responding!

      I have located several versions of recursive array searches. What is stumping me is the regex. All these recursive search functions look for exact matches. I need to search for characters embedded in the needle.

      And its not the regex that is the problem for me either. Its combining the two. A recursive array search for a regular expression.

      BUT I aint giving up yet! I have plenty of regex functions to work with.. let me see shat I can come up with..

      But thanks again for pointing me in the regex direction which i forgot about..

        Got it.. I just converted the array into a string. Then used the preg_match to locate the desired characters and report them.

          2 years later
          Write a Reply...