Home > Backend Development > PHP Tutorial > Sharing of algorithm for selecting three from three groups in sports lottery_PHP tutorial

Sharing of algorithm for selecting three from three groups in sports lottery_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 10:37:12
Original
1054 people have browsed it

Copy code The code is as follows:

function arrange($arr){
$new_arr = array();
$c = count($arr);
foreach($arr as $key=>$vo){
$lin = $arr;
array_splice($lin,$key,1) ;
for($l=0;$l<$c-1;$l++){
$larr = array();
$larr[] = $lin[$l];
$larr[] = $vo;
$larr[] = $vo;
$new_arr[] = $larr;
}
}
return $new_arr;
}
$arr = array(1,2,3,4);
$r = arrange($arr);
print_r($r);

The result obtained is:

Copy the code The code is as follows:

Array
(
[0 ] => Array
(
[0] => 2
[1] => 1
[2] => 1
)

[1] => Array
(
[0] => 3
[1] => 1
[2] => 1
)

[2] => Array
(
[0] => 4
[1] => 1
[2] => 1
)

[3] => Array
(
[0] => 1
[1] => 2
[2] => 2
)

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/736789.htmlTechArticleCopy the code The code is as follows: function arrange($arr){ $new_arr = array(); $c = count( $arr); foreach($arr as $key=$vo){ $lin = $arr; array_splice($lin,$key,1); for($l=0;$l$c-1;$l++) { $...
Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template