note 99203 modified in function.array-search by danbrown
| From: | danbrown@php.net | Date: | Tue, 03 Aug 2010 13:00:46 +0000 |
| Subject: | note 99203 modified in function.array-search by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-171352@lists.php.net to get a copy of this message | ||
This a simple and lazy lazy method to search a key name in an array by pattern, and return the value
if it isn't empty.
<?php
function array_search_key($p, $a)
{
foreach ($a as $k => $v) {
if(strstr($k, $p)){
if(!empty($v) || $v > 0){
return $v;
}
}
}
}
?>
--was--
This a simple and lazy lazy method to search a key name in an array by pattern, and return the value
if it isn't empty.
function array_search_key($p, $a)
{
foreach ($a as $k => $v) {
if(strstr($k, $p)){
if(!empty($v) || $v > 0){
return $v;
}
}
}
}
http://php.net/manual/en/function.array-search.php