note 119962 deleted from function.key by nikic

From: Date: Thu, 11 Oct 2018 21:05:36 +0000
Subject: note 119962 deleted from function.key by nikic
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-209429@lists.php.net to get a copy of this message
Note Submitter: vincphil54800 at gmail dot com ---- If you want to return the key on an associative array to get the first occurence of this array for exemple and if you don't know the key of the element that you search, it's impossible to find it without create you're own fonction, you can use for example : /** * Retourne la premiére clé/valeur d'un tableau (notament utile pour les tableaux associatifs) * @param array $tab un tableau * @param int $mode 0 => renvoie la premiére valeur du tableau, 1=> renvoie la premiére clé du tableau * @return mixed la premiére occurence d'un tableau */ public static function firstKey($tab,$mode = 0) { foreach($tab as $key=>$values) { if(is_array($values)) { self::firstKey($values); } if($mode == 0) { return $values; } elseif($mode == 1) { return $key; } } return null; }

« previous php.notes (#209429) next »