note 103983 added to function.in-array
| From: | cousinka at gmail dot com | Date: | Sun, 15 May 2011 21:26:07 +0000 |
| Subject: | note 103983 added to function.in-array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-179740@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 or
combination of these
Here ws fixed the error of object orient programming, I removed the "$this->" before
recall the function for recursion
<?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 the element is in array, else check next
element
if( ( is_array( $array_element ) || is_object( $array_element ) ) &&
in_multiarray( $elem, $array_element ) )
{
return TRUE;
exit;
}
}
}
// if isn't in array return FALSE
return FALSE;
}
?>
----
Server IP: 89.251.21.32
Probable Submitter: 188.173.141.107
----
Manual Page -- http://www.php.net/manual/en/function.in-array.php
Edit -- https://master.php.net/note/edit/103983
Del: integrated -- https://master.php.net/note/delete/103983/integrated
Del: useless -- https://master.php.net/note/delete/103983/useless
Del: bad code -- https://master.php.net/note/delete/103983/bad+code
Del: spam -- https://master.php.net/note/delete/103983/spam
Del: non-english -- https://master.php.net/note/delete/103983/non-english
Del: in docs -- https://master.php.net/note/delete/103983/in+docs
Del: other reasons-- https://master.php.net/note/delete/103983
Reject -- https://master.php.net/note/reject/103983
Search -- https://master.php.net/manage/user-notes.php