Created
January 15, 2013 11:37
-
-
Save ferminhg/4538021 to your computer and use it in GitHub Desktop.
PHP: buscar dentro de un array de objectos un valor para una key
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Busca tipo de noticias por valor | |
* @param $key | |
* @param $value | |
*/ | |
public static function search($key, $value) | |
{ | |
$atp = self::getAll(); | |
$ret = null; | |
foreach ($atp as $object) { | |
$objVars = get_object_vars($object); | |
if (isset($objVars[$key]) && $objVars[$key] == $value) { | |
$ret = $object; | |
break; | |
} | |
} | |
return $ret; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment