note 109893 deleted from function.array-map by danbrown

From: Date: Fri, 31 Aug 2012 15:35:00 +0000
Subject: note 109893 deleted from function.array-map by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-190306@lists.php.net to get a copy of this message
Note Submitter: djafferian at sos dot ri dot gov ---- 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); } ?>

« previous php.notes (#190306) next »