debz89uk Posted February 5, 2011 Share Posted February 5, 2011 I have any array $DF containing numeric variables, I want the minimum value of the array stored in $val but ignoring any zeros i.e. the lowest number that is not 0. Is this possible? Link to comment https://forums.phpfreaks.com/topic/226838-minarray-but-ignoring-0s/ Share on other sites More sharing options...
jcbones Posted February 5, 2011 Share Posted February 5, 2011 Pass the array through array values, then to the min function. $arr = array_values($DF); //array values with no second argument, strips out any value that is equivalent to boolean false. This includes integer 0, or string 0. $val = min($arr); Link to comment https://forums.phpfreaks.com/topic/226838-minarray-but-ignoring-0s/#findComment-1170460 Share on other sites More sharing options...
ignace Posted February 6, 2011 Share Posted February 6, 2011 Pass the array through array values, then to the min function. $arr = array_values($DF); //array values with no second argument, strips out any value that is equivalent to boolean false. This includes integer 0, or string 0. $val = min($arr); I think you are referring to array_filter as array_values will just return all values from an array including zero's and other false-like values. Link to comment https://forums.phpfreaks.com/topic/226838-minarray-but-ignoring-0s/#findComment-1170577 Share on other sites More sharing options...
jcbones Posted February 6, 2011 Share Posted February 6, 2011 Yes, ignace, I meant array_filter() sorry. Thinking one thing, typed another. Link to comment https://forums.phpfreaks.com/topic/226838-minarray-but-ignoring-0s/#findComment-1170780 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.