Home > OS >  How to get non zero positive numbers form array in php
How to get non zero positive numbers form array in php

Time:01-18

I have an array for which i need to get non zero positive numbers

$arr = array(
-100,-2,0,100,1000
);

Desire output:

$arr = array(
100,1000
);

Thank's

CodePudding user response:

You could use following code

$output = array_map($input, function ($value) {
            if (is_numeric($value) && $value > 0) {
                return $value;
            }
        });

CodePudding user response:

Something like this ?

$arr = array(
    -100,-2,0,100,1000
    );
$arr =  array_filter($arr, function ($x) { return $x > 0; });
exit(var_dump($arr));
  •  Tags:  
  • Related