問題描述
我剛剛使用 array_filter 從數(shù)組中刪除了只有值 '' 的條目,現(xiàn)在我想根據(jù)從 0 開始的占位符對(duì)其應(yīng)用某些轉(zhuǎn)換,但不幸的是它仍然保留了原始索引.我看了一會(huì)兒,什么也沒看到,也許我只是錯(cuò)過(guò)了明顯的,但我的問題是......
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...
如何輕松地將數(shù)組的索引重置為從 0 開始并在新數(shù)組中按順序排列,而不是保留舊索引?
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?
推薦答案
如果你調(diào)用 array_values
在您的數(shù)組上,它將從零重新索引.
If you call array_values
on your array, it will be reindexed from zero.
這篇關(guān)于在 array_filter() 之后,如何重置鍵以從 0 開始按數(shù)字順序排列的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!