问题描述
我刚刚使用 array_filter 从数组中删除了只有值 '' 的条目,现在我想根据从 0 开始的占位符对其应用某些转换,但不幸的是它仍然保留了原始索引.我看了一会儿,什么也没看到,也许我只是错过了明显的,但我的问题是......
I just used array_filter to remove entries that had only the value '' from an array, and now I want to apply certain transformations on it depending on the placeholder starting from 0, but unfortunately it still retains the original index. I looked for a while and couldn't see anything, perhaps I just missed the obvious, but my question is...
如何轻松地将数组的索引重置为从 0 开始并在新数组中按顺序排列,而不是保留旧索引?
How can I easily reset the indexes of the array to begin at 0 and go in order in the NEW array, rather than have it retain old indexes?
推荐答案
如果你调用 array_values
在您的数组上,它将从零重新索引.
If you call array_values
on your array, it will be reindexed from zero.
这篇关于在 array_filter() 之后,如何重置键以从 0 开始按数字顺序排列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!