After array_filter(), how can I reset the keys to go in numerical order starting at 0(在 array_filter() 之后,如何重置键以从 0 开始按数字顺序排列)
问题描述
我刚刚使用 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 开始按数字顺序排列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 array_filter() 之后,如何重置键以从 0 开始按数


基础教程推荐
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 如何替换eregi() 2022-01-01