0

lets say i have a get variable:

$goto=$_GET['goto'];

and i have a array

$sections= array('fail' => fail());

how would i make it so when the $goto=fail, it does the function fail from the array?

4
Contributors
8
Replies
9
Views
6 Years
Discussion Span
Last Post by Killer.bee
0
function foo()
{
echo "thanks for calling";
}
$goto=$_GET['goto'];
$sections= array('fail','success');
if(in_array($goto,$sections))
{
foo();
  //call the function u want to call here
}
0
function foo($goto)
{
echo "thanks for calling".$goto;
}
$goto=$_GET['goto'];
$sections= array('fail','success');
if(in_array($goto,$sections))
{
foo($goto);
  //call the function u want to call here
}

Hope this is what u r looking for
PS-Mark the thread as solved if your porblem is solved..

0

Ok, what I want is goto is the get variable. I want an Array that has different things pointing to functions. And if the goto is one of the things, then it does the function the goto it pointing to

0

look at my post again. It does what you want. If you look at YOUR post you have: $sections= array('fail' => fail()); what you are doing there is initializing $sections to whavever fail() returns.

To clarify, if you have:

<?php
function fail(){
return 'hello';
}
$sections= array('fail' => fail());
?>

What YOU are really doing is initializing $sections to "hello".

Based on your description, what you are HOPING to do is to be able to call fail() based on whatever $_GET['goto'] has, which is what I gave you.

If you are going to have:
$sectionsfail[/B]'] call fail()

it will be simpler to just "LIST" the functions in an array: $sections=array("fail"); and if the value of $goto is in $sections, just call $goto();

0

@tcollins412-The code posted by hielo and tomato.pgn is doing the same thing what you have asked for.....
If you want something different then give a suitable example to explain us your problem...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.