note 93301 added to function.array-map

From: Date: Wed, 02 Sep 2009 02:34:14 +0000
Subject: note 93301 added to function.array-map
Groups: php.notes 
Request: Send a blank email to php-notes+get-160147@lists.php.net to get a copy of this message
My English is weak but I want to share my code. I want to change formation of array but when I use null is callback function in array_map(). It has problem in result so I write new small function for it. function array_change_formation($arr=array()) { $new_arr = array(); foreach($arr as $k => $v) foreach($v as $k2 => $v2) $new_arr[$k2][$k] = $v[$k2]; return $new_arr; } Input: Array ( [Human] => Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 ) [Pet] => Array ( [0] => Cat [1] => Dog [2] => Rabbit [3] => Rat ) ) OutPut: Array ( [0] => Array ( [Human] => 1 [Pet] => Cat ) [1] => Array ( [Human] => 2 [Pet] => Dog ) [2] => Array ( [Human] => 3 [Pet] => Rabbit ) [3] => Array ( [Human] => 4 [Pet] => Rat ) ) I hope it can useful. ---- Server IP: 203.121.145.123 Probable Submitter: 125.27.242.68 ---- Manual Page -- http://www.php.net/manual/en/function.array-map.php Edit -- https://master.php.net/note/edit/93301 Del: integrated -- https://master.php.net/note/delete/93301/integrated Del: useless -- https://master.php.net/note/delete/93301/useless Del: bad code -- https://master.php.net/note/delete/93301/bad+code Del: spam -- https://master.php.net/note/delete/93301/spam Del: non-english -- https://master.php.net/note/delete/93301/non-english Del: in docs -- https://master.php.net/note/delete/93301/in+docs Del: other reasons-- https://master.php.net/note/delete/93301 Reject -- https://master.php.net/note/reject/93301 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#160147) next »