note 35502 deleted from ref.array by sniper

From: Date: Sat, 18 Oct 2003 17:59:49 +0000
Subject: note 35502 deleted from ref.array by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-58817@lists.php.net to get a copy of this message
Note Submitter: vital(#)zemfira.org ---- function to get all value combinations of one array into another array: <?php $a=array("mobile", "phone", "Motorola"); $r=array(); function arraycombination( &$fromArray,&$resultArray,$lastValue='',$usedValue=array() ){ for ($i=0;$i<count($fromArray);$i++) if (!in_array($i,$usedValue)) { $value=($lastValue!=''?$lastValue.' ':'').$fromArray[$i]; $resultArray[]=$value; $lused=$usedValue; $usedValue[]=$i; arraycombination($fromArray,$resultArray,$value,$usedValue); $usedValue=$lused; } } arraycombination($a,$r); print_r($r); ?> as result you get: Array ( [0] => mobile [1] => mobile phone [2] => mobile phone Motorola [3] => mobile Motorola [4] => mobile Motorola phone [5] => phone [6] => phone mobile [7] => phone mobile Motorola [8] => phone Motorola [9] => phone Motorola mobile [10] => Motorola [11] => Motorola mobile [12] => Motorola mobile phone [13] => Motorola phone [14] => Motorola phone mobile )

« previous php.notes (#58817) next »