Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.