note 80900 added to ref.array
| From: | csorfab at gmail dot com | Date: | Wed, 06 Feb 2008 06:26:10 +0000 |
| Subject: | note 80900 added to ref.array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-135811@lists.php.net to get a copy of this message | ||
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;
}
}
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 193.224.27.126
----
Manual Page -- http://www.php.net/manual/en/ref.array.php
Edit -- https://master.php.net/note/edit/80900
Del: integrated -- https://master.php.net/note/delete/80900/integrated
Del: useless -- https://master.php.net/note/delete/80900/useless
Del: bad code -- https://master.php.net/note/delete/80900/bad+code
Del: spam -- https://master.php.net/note/delete/80900/spam
Del: non-english -- https://master.php.net/note/delete/80900/non-english
Del: in docs -- https://master.php.net/note/delete/80900/in+docs
Del: other reasons-- https://master.php.net/note/delete/80900
Reject -- https://master.php.net/note/reject/80900
Search -- https://master.php.net/manage/user-notes.php