note 109893 added to function.array-map

From: Date: Fri, 31 Aug 2012 15:00:28 +0000
Subject: note 109893 added to function.array-map
Groups: php.notes 
Request: Send a blank email to php-notes+get-190305@lists.php.net to get a copy of this message
Regarding the two dimensional matrix transpose provided by radist-hack at yandex dot ru 01-Nov-2008 07:37, a complete solution which handles special cases not properly handled by array_map can be found here : http://rosettacode.org/wiki/Matrix_transposition#PHP <?php function transpose($matrix) { // special case: empty matrix if (count($matrix) == 0) { return array(); } // special case: one row matrix if (count($matrix) == 1) { return array_chunk($matrix[0], 1); } // general case: two or more rows array_unshift($matrix, null); return call_user_func_array('array_map', $matrix); } ?> ---- Server IP: 192.41.42.26 Probable Submitter: 198.7.225.122 ---- Manual Page -- http://www.php.net/manual/en/function.array-map.php Edit -- https://master.php.net/note/edit/109893 Del: integrated -- https://master.php.net/note/delete/109893/integrated Del: useless -- https://master.php.net/note/delete/109893/useless Del: bad code -- https://master.php.net/note/delete/109893/bad+code Del: spam -- https://master.php.net/note/delete/109893/spam Del: non-english -- https://master.php.net/note/delete/109893/non-english Del: in docs -- https://master.php.net/note/delete/109893/in+docs Del: other reasons-- https://master.php.net/note/delete/109893 Reject -- https://master.php.net/note/reject/109893 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#190305) next »