This is my first post, so please be indulgent/lenient.
This array is steps enumeration of an embroidery program
And I have to keep "0" values between not null steps and to do not take null values after
$oldArray = Array
("1278","1297","1278","1000","0","1000","1212","1001","1212","1278","1000",
"0","1297","1001","1000","0","1001","1278","1000","1001","1001","1278",
"0","1000","1001","0","0","0","0","0","0","0","0","0","0",
"0","0","0","0","0","0","0","0","0","0","0","0","0","0"
);
I reverse it a first time and find the first not null value :
$arrayReversed = array_reverse($oldArray);
$lastKey = 48;
foreach ($arrayReversed as $key => $value) {
# If the value is not empty
if (!empty($value)) {
[FR] -> remplir un nouveau tableau avec les valeurs en partant de l'index "$key" jusqu'a "$lastKey"
[ENG] -> fill a new array with values starting from the first key with not null value to the last key Edit : Here was my error
$sequencesFromEnd[] = array_slice($arrayReversed,$key,$lastKey);
I have it corrected with this code :
$sequencesFromEnd = array_slice($arrayReversed,$key,$lastKey);
break;
}
$key++;
}
Edit : Then It works like I've expected !
Then I want to Reverse "again" the array with values for have steps in the right order and this code is not working :
//First try
$stepsInRightOrder = array_reverse($sequencesFromEnd);
// Second try
//array_reverse($stepsInRightOrder);
Second try commented because it is a no-op.
Unfortunately, the array stay like it is implemented in the "foreach" loop ...
Thanks a lot by advance !!