note 69965 modified in function.array-search by danbrown
| From: | danbrown@php.net | Date: | Wed, 29 Apr 2009 13:00:15 +0000 |
| Subject: | note 69965 modified in function.array-search by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-153983@lists.php.net to get a copy of this message | ||
My Function to search a Multidimensional array.
Pass in :
$theNeedle as what you want to find.
$theHaystack as the array
$keyToSearch as what key in the array you want to find the value in.
<?php
function myMulti_Array_Search($theNeedle, $theHaystack, $keyToSearch)
{
foreach($theHaystack as $theKey => $theValue)
{
$intCurrentKey = $theKey;
if($theValue[$keyToSearch] == $theNeedle)
{
return $intCurrentKey ;
}
else
{
return 0;
}
}
}
?>
--was--
My Function to search a Multidimensional array.
Pass in :
$theNeedle as what you want to find.
$theHaystack as the array
$keyToSearch as what key in the array you want to find the value in.
<?
function myMulti_Array_Search($theNeedle, $theHaystack, $keyToSearch)
{
foreach($theHaystack as $theKey => $theValue)
{
$intCurrentKey = $theKey;
if($theValue[$keyToSearch] == $theNeedle)
{
return $intCurrentKey ;
}
else
{
return 0;
}
}
}
?>
http://php.net/manual/en/function.array-search.php