这是我的第一篇文章,所以请宽容/宽容。
该数组是一个刺绣程序的步骤枚举
而且我必须在非空步骤之间保持“0”值,并且在之后不要取空值
$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"
);
我第一次反转它并找到第一个非空值:
$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] -> 用从第一个非空值的键到最后一个键的值填充一个新数组 编辑:这是我的错误
$sequencesFromEnd[] = array_slice($arrayReversed,$key,$lastKey);
我用这段代码纠正了它:
$sequencesFromEnd = array_slice($arrayReversed,$key,$lastKey);
break;
}
$key++;
}
编辑:然后它就像我预期的那样工作!
然后我想用正确的顺序来“再次”反转具有值的数组,并且此代码不起作用:
//First try
$stepsInRightOrder = array_reverse($sequencesFromEnd);
// Second try
//array_reverse($stepsInRightOrder);
第二次尝试评论了,因为它是无操作的。
不幸的是,数组仍然像在“foreach”循环中实现的那样......
非常感谢提前!