note 101285 added to function.array-shift

From: Date: Tue, 07 Dec 2010 18:14:23 +0000
Subject: note 101285 added to function.array-shift
Groups: php.notes 
Request: Send a blank email to php-notes+get-174693@lists.php.net to get a copy of this message
Just for fun - and for PHP4 ;-): A function combining arrays using NULL as value if the value is missing (more keys than values) and the next possible number as key if the key is missing (more values than keys). As a special effect it also works with only one array, using the values of that array as keys and as values. Should work with any possible array. Keys are typecasted to strings before use. With duplicate keys previous key-value-pairs will be overwritten. function array_combine_4($keys,$vals=NULL) { $comb = array(); if (!is_array($vals)) $vals = $keys; foreach ($keys as $key) $out[(string)$key] = array_shift($vals); while ($val = array_shift($vals)) $out[] = $val; return($out); } ---- Server IP: 85.214.154.209 Probable Submitter: 80.153.162.95 ---- Manual Page -- http://www.php.net/manual/en/function.array-shift.php Edit -- https://master.php.net/note/edit/101285 Del: integrated -- https://master.php.net/note/delete/101285/integrated Del: useless -- https://master.php.net/note/delete/101285/useless Del: bad code -- https://master.php.net/note/delete/101285/bad+code Del: spam -- https://master.php.net/note/delete/101285/spam Del: non-english -- https://master.php.net/note/delete/101285/non-english Del: in docs -- https://master.php.net/note/delete/101285/in+docs Del: other reasons-- https://master.php.net/note/delete/101285 Reject -- https://master.php.net/note/reject/101285 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#174693) next »