mwl707 Posted June 28, 2009 Share Posted June 28, 2009 Can somebody help me please , Can I use a variable with the MIN function in php? I have altered the code slightly so it is more universal but it is a bit like $strings = "2,4,8,76,2,4,3,5" ; $result = min($strings) ; echo " Min result is $result " ; I have tried encapsulating the $strings variable with " and ' but still no result Can anyone offer some advice please ? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/163981-help-with-min/ Share on other sites More sharing options...
Ken2k7 Posted June 28, 2009 Share Posted June 28, 2009 Since $strings is just one string, it doesn't make sense to ask so much of PHP to decipher how to find the lowest number in it. You can separate each number in the strings into an array and pass that to the min function. <?php $strings = "2,4,8,76,2,4,3,5"; $nums = explode(',',$strings); $min = min($nums); echo sprintf('Min result is %s', $min); Quote Link to comment https://forums.phpfreaks.com/topic/163981-help-with-min/#findComment-865076 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.