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

How to generate continuous data in PHP

WBOY
Release: 2016-07-06 13:53:43
Original
1173 people have browsed it

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>
Copy after login

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

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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template