Home >php教程 >php手册 >体育彩票排列三组选三算法分享

体育彩票排列三组选三算法分享

WBOY
WBOYOriginal
2016-06-06 20:24:151825browse

这篇文章主要介绍了php实现体育彩票排列三组选三算法示例,根据用户投注的多个号码,拆成单注的数组形式

复制代码 代码如下:


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   $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);

得到的结果是:

复制代码 代码如下:


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
)

Statement:
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