note 80900 deleted from ref.array by levim

From: Date: Tue, 06 May 2014 22:11:59 +0000
Subject: note 80900 deleted from ref.array by levim
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-199473@lists.php.net to get a copy of this message
Note Submitter: csorfab at gmail dot com ---- Here's a function I wrote to combine the values in an array in all different ways, and which returns a two-dimensional array as a byref result. E.g. if called: comb(array(1, 2, 3), $r); then $r would be: 1 2 3 1 3 2 2 1 3 2 3 1 3 1 2 3 2 1 <?php function comb($arr, &$rarr, $vtemp = array()){ foreach($arr as $key => $value){ $vtemp2 = $vtemp; $vtemp2[] = $value; $atemp = $arr; unset($atemp[$key]); if(count($atemp) > 0){ comb($atemp, $rarr, $vtemp2); } else { $t = array(); foreach($vtemp2 as $val){ $t[] = $val; } $rarr[] = $t; } } } ?>

« previous php.notes (#199473) next »