Jump to content

Help with MIN


mwl707

Recommended Posts

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

 

 

Link to comment
https://forums.phpfreaks.com/topic/163981-help-with-min/
Share on other sites

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);

Link to comment
https://forums.phpfreaks.com/topic/163981-help-with-min/#findComment-865076
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.