数组中只有较高的值作为变量号

时间:2018-02-07 10:28:38

标签: php arrays

我有数字和可变数字的数组:

$a = array(1,2,3,4,5,6,7,8,9,10);
$v = 5;

我需要结果所有数字,如果高于$ v:

$result = ?? //array(6,7,8,9,10)

1 个答案:

答案 0 :(得分:2)

<?php

$a = array(1,2,3,4,5,6,7,8,9,10);
$v = 5;

foreach($a as $value){
    if($value > $v ){
        $new[] = $value;
    }
}

echo "<pre>";
print_r($new);