I have done a lot of research on google about it but I don't know how to achieve that in PHP. Actually I have an array with values and for each values I would like to get 5 new values incremented of 1.
Exemple :
$valueseg = array( 0 => 2510 , 1 => 1700);
I would like to get this result :
$valueseg = array( 0 => 2510, 1 => 2511, 2 => 2512, 3 => 2513, 4 => 2514 , 5 => 2515, 6 => 1700, , 7 => 1701, , 8 => 1702, , 9 => 1703, 10 => 1704 , 11 => 1705);
I tried to do that with a foreach and a for loop but I can't retrieve an array.
$tabasc = array();
foreach($valueseg as $key => $value){
for($i = 0; $i < 5; $i++){
$tabasc[$i] = $value + $i ;
}
}
With an echo inside the for loop I have a result inline like this : 2478247924802481248225102511251225132514
And if I try to do a var_dump of $tabasc it shows me values incremented of 1 only for the first value of $valueseg.
Do you know how to do that ?
Thanks
Do it like below:-
<?php
$valueseg = array( 0 => 2510 , 1=> 1700);
$final_array = array(); //create a new array
foreach($valueseg as $values){ // iterate over your original array
for($i=1;$i<=5;$i++){ // loop 5 times
$final_array[] = $values+$i; //add incremented $i value to original value and assign to new array
}
}
print_r($final_array); // print new array
Output:- https://eval.in/829546
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments