note 119962 added to function.key

From: Date: Wed, 28 Sep 2016 22:13:17 +0000
Subject: note 119962 added to function.key
Groups: php.notes 
Request: Send a blank email to php-notes+get-206699@lists.php.net to get a copy of this message
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; } ---- Server IP: 72.52.91.14 Probable Submitter: 193.49.162.15 ---- Manual Page -- http://php.net/manual/en/function.key.php Edit -- https://master.php.net/note/edit/119962 Del: integrated -- https://master.php.net/note/delete/119962/integrated Del: useless -- https://master.php.net/note/delete/119962/useless Del: bad code -- https://master.php.net/note/delete/119962/bad+code Del: spam -- https://master.php.net/note/delete/119962/spam Del: non-english -- https://master.php.net/note/delete/119962/non-english Del: in docs -- https://master.php.net/note/delete/119962/in+docs Del: other reasons-- https://master.php.net/note/delete/119962 Reject -- https://master.php.net/note/reject/119962 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#206699) next »