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