note 92355 modified in function.array-key-exists by danbrown

From: Date: Tue, 21 Jul 2009 13:04:14 +0000
Subject: note 92355 modified in function.array-key-exists by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-158537@lists.php.net to get a copy of this message
The multi_array_key_exists() function posted by alishahnovin at hotmail dot com [which has since been removed] does not always return the expected result. This modified version does. <?php /** * multi_array_key_exists function. * * @param mixed $needle The key you want to check for * @param mixed $haystack The array you want to search * @return bool */ function multi_array_key_exists( $needle, $haystack ) { foreach ( $haystack as $key => $value ) : if ( $needle == $key ) return true; if ( is_array( $value ) ) : if ( multi_array_key_exists( $needle, $value ) == true ) return true; else continue; endif; endforeach; return false; } ?> --was-- The multi_array_key_exists() function posted by alishahnovin at hotmail dot com ( http://uk3.php.net/manual/en/function.array-key-exists.php#75411 ) does not always return the expected result. This modified version does. <?php /** * multi_array_key_exists function. * * @param mixed $needle The key you want to check for * @param mixed $haystack The array you want to search * @return bool */ function multi_array_key_exists( $needle, $haystack ) { foreach ( $haystack as $key => $value ) : if ( $needle == $key ) return true; if ( is_array( $value ) ) : if ( multi_array_key_exists( $needle, $value ) == true ) return true; else continue; endif; endforeach; return false; } ?> http://php.net/manual/en/function.array-key-exists.php

« previous php.notes (#158537) next »