0

I have a set of variables that have randomly assigned values.

E.g.,

$a = 1;
$b = -1;
$c = 2;

And I have a script that corresponds to each variable.

E.g.,

a.php for $a
b.php for $b
c.php for $c

I want to run the script that corresponds with the variable that has the greatest value. So, in this case, I want to run c.php because $c has the greatest value among the three variables.

Thank you so much, Peter

Edit: This is what I have. I've basically put the variables in an array and sorted them from highest to lowest according to the value. But this doesn't solve my problem. I want to run a corresponding php file.

$var = array( 'a' => $a, 'b' => $b, 'c' => $c);
arsort($var);
6
  • 3
    Have you tried something ? Commented Apr 26, 2015 at 18:14
  • What do you want do say with 'run' the script? Commented Apr 26, 2015 at 18:35
  • 2
    Welcome to SO. With a better explanation, surely you find the solution in a jiffy! Recomended start: stackoverflow.com/tour and stackoverflow.com/help/how-to-ask. I invite you to rethink the question by explaining better what you want to achieve and what you've done so far. Commented Apr 26, 2015 at 18:49
  • I have a php script corresponding to each variable. I want to "call" or "execute" or "run" the php script that corresponds to the variable that has the highest value. (I'm a noob, so maybe I'm getting the wording wrong.) Commented Apr 26, 2015 at 18:58
  • 1
    Now what do you mean with "run", include ? (Can you make an example what is in the file which you want to run?) Commented Apr 26, 2015 at 18:58

1 Answer 1

1

You can get the greatest value using:

$a = 1;
$b = -1;
$c = 2;

$files = array(
    $a => 'a.php',
    $b => 'b.php',
    $c => 'c.php'
);

ksort($files);

echo 'Correct file: ' . array_pop($files);

References:

ksort()

array_pop()

Sign up to request clarification or add additional context in comments.

13 Comments

This doesn't answer OP's question! Where is the relation to the variables and the file names?!
Still only with the greatest value he can't execute file "c.php" then?!
@Rizier123, He needs to specify better what mean 'execute', can be an include, curl and other. With the correct file, i think he can go ahead.
But how does he gets the file c.php with the value 3 ?
@Rizier123, I made another improvement
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.