Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

check if is in array a value bigger than zero

Tags:

php

How do I check if in my array values is there a value bigger than 0?

Example:

array code {'0', '0', '0'}

Returns false.

array code_ii {'0', '1', '0'}

Returns true.

like image 517
vinoli Avatar asked Dec 11 '22 00:12

vinoli


2 Answers

This should work for you:

(If one array element is bigger than 0 the entire array sum is bigger than 0 and you can return true)

<?php

    $arr = array(0, 0 , 1);


    if(array_sum($arr) > 0)
        echo "true";
    else
        echo "false";

?>

Output:

true
like image 71
Rizier123 Avatar answered Dec 25 '22 19:12

Rizier123


You can use the following technique to get the value bigger than zero if present in array.

if (max(array(0,1,0)) > 0)
    echo 'Array has value greater than 0';

Hope it will solve your problem or task. Thanks, Looking forward for the comments or queries if any.

like image 29
PHP Team Avatar answered Dec 25 '22 19:12

PHP Team