mardi 26 janvier 2016

PHP: range and foreach

I'm working with percents and rand(), I'm trying to create an array from 0 to 25 then 25 to 50 then 50 to 80. But I got this array:

[0] => 55
[1] => 56
[2] => 57
[3] => 58
[4] => 59
[5] => 60
[6] => 61
[7] => 62
[8] => 63
[9] => 64
[10] => 65
[11] => 66
[12] => 67
[13] => 68
[14] => 69
[15] => 70
[16] => 71
[17] => 72
[18] => 73
[19] => 74
[20] => 75
[21] => 76
[22] => 77
[23] => 78
[24] => 79
[25] => 80

I want to create an array from 0 to 80. My code is:

foreach($list_percents as $redir) {
    $percent_array=range($inicial,($inicial+$redir->percent));
    $percent_array=array_fill($inicial, $redir->percent, $redir->url);
    $inicial=($inicial+$redir->percent);
}
print_r($percent_array);




Aucun commentaire:

Enregistrer un commentaire