note 99294 modified in function.in-array by danbrown

From: Date: Mon, 09 Aug 2010 15:48:21 +0000
Subject: note 99294 modified in function.in-array by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-171491@lists.php.net to get a copy of this message
Here is a function which returns TRUE if a value exists in a multi array or in a multi object <?php function in_multiarray($elem, $array) { // if the $array is an array or is an object if( is_array( $array ) || is_object( $array ) ) { // if $elem is in $array object if( is_object( $array ) ) { $temp_array = get_object_vars( $array ); if( in_array( $elem, $temp_array ) ) return TRUE; } // if $elem is in $array return true if( is_array( $array ) && in_array( $elem, $array ) ) return TRUE; // if $elem isn't in $array, then check foreach element foreach( $array as $array_element ) { // if $array_element is an array or is an object call the in_multiarray function to this element // if in_multiarray returns TRUE, than return is in array, else check next element if( ( is_array( $array_element ) || is_object( $array_element ) ) && $this->in_multiarray( $elem, $array_element ) ) { return TRUE; exit; } } } // if isn't in array return FALSE return FALSE; } ?> --was-- Here is a function which returns TRUE if a value exists in a multi array or in a multi object function in_multiarray($elem, $array) { // if the $array is an array or is an object if( is_array( $array ) || is_object( $array ) ) { // if $elem is in $array object if( is_object( $array ) ) { $temp_array = get_object_vars( $array ); if( in_array( $elem, $temp_array ) ) return TRUE; } // if $elem is in $array return true if( is_array( $array ) && in_array( $elem, $array ) ) return TRUE; // if $elem isn't in $array, then check foreach element foreach( $array as $array_element ) { // if $array_element is an array or is an object call the in_multiarray function to this element // if in_multiarray returns TRUE, than return is in array, else check next element if( ( is_array( $array_element ) || is_object( $array_element ) ) && $this->in_multiarray( $elem, $array_element ) ) { return TRUE; exit; } } } // if isn't in array return FALSE return FALSE; } http://php.net/manual/en/function.in-array.php

« previous php.notes (#171491) next »