根据第一个字符取消设置数组元素
我试图找到一种方法来取消设置元素,如果第一个字符是某个字母,在本例中是字母 D...我不确定是否有一个数组函数可以执行此类操作,或者是否有 preg 替换会成功吗?
[0] => Aaron [1] => Bob [2] => Carl [3] => Dale [4] => Devin [5] => Dylan
取消设置所有以字母“D”开头的单词将导致:
[0] => Aaron [1] => Bob [2] => Carl
Im trying to find a way to unset an element if the first character is a certain letter, in this case the letter D... I'm not sure if there is an array function to do something of the sort or if a preg replace would do the trick?
[0] => Aaron [1] => Bob [2] => Carl [3] => Dale [4] => Devin [5] => Dylan
Unset all words that start with letter "D" Would result in:
[0] => Aaron [1] => Bob [2] => Carl
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
手动循环已经完成了任务。但作为单行选项:
A manual loop accomplishes the task already. But as one-liner option:
您可以使用 array_filter 函数:
如果您要使用的字母过滤方式将会改变,你可以构建一个非常基本的过滤类:
You could use the array_filter function:
If the letter you are going to be filtering by is going to change, you can build a really basic filtering class:
是一种适合您的方法。
Is one method that could work well for you.