peter11 Posted August 13, 2010 Share Posted August 13, 2010 Why is this not correct? <?php $newphrase = 1234567; echo (max($newphrase)); ?> Quote Link to comment https://forums.phpfreaks.com/topic/210638-max-quetion/ Share on other sites More sharing options...
JonnoTheDev Posted August 13, 2010 Share Posted August 13, 2010 Because the function max() takes an array, or series of values as its parameter, not a string. i.e echo max(1,2,3,4); echo max(array(1,2,3,4)); Quote Link to comment https://forums.phpfreaks.com/topic/210638-max-quetion/#findComment-1098834 Share on other sites More sharing options...
peter11 Posted August 13, 2010 Author Share Posted August 13, 2010 how can i show the highest number in the string? Quote Link to comment https://forums.phpfreaks.com/topic/210638-max-quetion/#findComment-1098839 Share on other sites More sharing options...
newbtophp Posted August 13, 2010 Share Posted August 13, 2010 how can i show the highest number in the string? <?php $newphrase = 1234567; preg_match_all('~\d{1}~', $newphrase, $a); echo max($a[0]); ?> Quote Link to comment https://forums.phpfreaks.com/topic/210638-max-quetion/#findComment-1098842 Share on other sites More sharing options...
JonnoTheDev Posted August 13, 2010 Share Posted August 13, 2010 <?php $newphrase = 1234567; echo max(str_split($newphrase)); ?> Quote Link to comment https://forums.phpfreaks.com/topic/210638-max-quetion/#findComment-1098843 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.