wrz 08

Szuka rekursywnie w głąb tablicy

Tag: phpxixek @ 08-09-2010 18:13
Bookmark and Share
    /*
     *
     * Szuka rekursywnie w głąb tablicy
     *
     * @param array $haystack tablica
     * @param string $needle wartość
     * @param string $index cecha
     * @return mixed
     *
     */
    function recursiveArraySearch($haystack, $needle, $index = null) {
        $aIt = new RecursiveArrayIterator($haystack);
        $it = new RecursiveIteratorIterator($aIt);

        while ($it->valid()) {
            if (((isset($index) AND ($it->key() == $index)) OR (!isset($index))) AND ($it->current() == $needle)) {
                return $aIt->key();
            }

            $it->next();
        }

        return false;
    }

Zostaw komentarz