peterhuynh Posted April 24, 2015 Share Posted April 24, 2015 I have a set of variables with randomly assigned integers. $a = 1; $b = 3; $c = -1; I put them in an array and sort them from highest to lowest. $all = array( 'a' => $a, 'b' => $b, 'c' => $c ); arsort($all); I want to do something with the highest variable only if it is greater than 0. How can I accomplish that? Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/295836-do-something-with-highest-variable-from-an-array-of-variables/ Share on other sites More sharing options...
cyberRobot Posted April 24, 2015 Share Posted April 24, 2015 You could use current() or array_shift to get the first element. Then run a simple if test. Quote Link to comment https://forums.phpfreaks.com/topic/295836-do-something-with-highest-variable-from-an-array-of-variables/#findComment-1509862 Share on other sites More sharing options...
Barand Posted April 24, 2015 Share Posted April 24, 2015 Instead of the sort you could find the highest value with max($all) Quote Link to comment https://forums.phpfreaks.com/topic/295836-do-something-with-highest-variable-from-an-array-of-variables/#findComment-1509868 Share on other sites More sharing options...
peterhuynh Posted April 25, 2015 Author Share Posted April 25, 2015 OP here: I could be more specific. The variables $a, $b, $c corresonding to three separate scripts: a.php, b.php, c.php. If, among the three variables, $a ends up having the greatest value, then I want to execture a.php. And if $b ends up having the greatest value, then I want to execute b.php. How can I do this? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/295836-do-something-with-highest-variable-from-an-array-of-variables/#findComment-1509895 Share on other sites More sharing options...
cyberRobot Posted April 28, 2015 Share Posted April 28, 2015 @peterhuynh - It depends on your setup. You could look into using a header() redirect. Or maybe you could import the script to execute with something like require(). Quote Link to comment https://forums.phpfreaks.com/topic/295836-do-something-with-highest-variable-from-an-array-of-variables/#findComment-1510180 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.