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

查看:90
本文介绍了如何删除小于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天全站免登陆