note 93301 deleted from function.array-map by googleguy

From: Date: Tue, 22 Oct 2013 11:16:36 +0000
Subject: note 93301 deleted from function.array-map by googleguy
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-197062@lists.php.net to get a copy of this message
Note Submitter: ethaizone at hotmail dot com ---- 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. <?php 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.

« previous php.notes (#197062) next »