Home >Backend Development >PHP Tutorial >How to generate continuous data in PHP

How to generate continuous data in PHP

WBOY
WBOYOriginal
2016-07-06 13:53:431176browse

I have a set of data 0 1 3 5 6 8 10
How to generate it 0 1 2 3 4 5 6 7 8 9 10

Reply content:

I have a set of data 0 1 3 5 6 8 10
How to generate it 0 1 2 3 4 5 6 7 8 9 10

<code>$a = [0,1,3,5,6,8,10];//原始数据
sort($a);
range(array_shift($a),array_pop($a));
</code>

Get the maximum value in the data, then foreach loop, the number of loops is the maximum value 1

Modification
$numbers = array(0, 1, 3, 5, 6, 8, 10);
$new = range(array_shift($numbers),end($numbers));
print_r($new);

$max=$a[0];
foreach($a as $b){
$max=($b<$max)?$max:$b;}
for( )Loop assignment

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