w3resource
php Programming Exercies

PHP Array Exercises : Return the lowest integer (not 0) from a list of numbers

PHP Array: Exercise-17 with Solution

Write a PHP function that returns the lowest integer that is not 0.

Sample Solution:

PHP Code:

<?php
function min_values_not_zero(Array $values) 
{
return min(array_diff(array_map('intval', $values), array(0)));
}
print_r(min_values_not_zero(array(-1,0,1,12,-100,1))."\n");
?>

Sample Output:

-100   

Flowchart:

Flowchart: Return the lowest integer (not 0) from a list of numbers

PHP Code Editor:

Contribute your code and comments through Disqus.

Previous: Write a PHP script to get the largest key in an array.
Next: Write a PHP function to floor decimal numbers with precision.

What is the difficulty level of this exercise?



New Content: Composer: Dependency manager for PHP, R Programming