如何删除数组中小于X的整数? [英] How to remove integers in array less than X?

查看:22
本文介绍了如何删除数组中小于X的整数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含 0 到 100 整数值的数组.我希望删除小于数字 X 的整数并保留等于或大于数字 X 的整数.

I have an array with integers of values from 0 to 100. I wish to remove integers that are less than number X and keep the ones that are equal or greater than number X.

推荐答案

使用笨重的 create_function 有点难看,但很直接:

A little ugly using the clunky create_function, but straight forward:

$filtered = array_filter($array, create_function('$x', 'return $x >= $y;'));

对于 PHP >= 5.3:

For PHP >= 5.3:

$filtered = array_filter($array, function ($x) { return $x >= $y; });

$y 设置为您想要的任何值.

Set $y to whatever you want.

这篇关于如何删除数组中小于X的整数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆