Skip to content

Instantly share code, notes, and snippets.

@ferminhg
Created January 15, 2013 11:37
Show Gist options
  • Save ferminhg/4538021 to your computer and use it in GitHub Desktop.
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
/**
* 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