0

Although I've read about it it still doesn't sink in when you will need to pass in a variable. I think I know how i just don't know for what reason. If someone could provide that information for me i would appreciate it. Also, is PHP variable passing more efficient than doing so in HTML? Thanks for your time and help.

Edited by Reliable: forgot something

3
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by Reliable
0

In what context are you referring?
Functions ?

function myFunction($var1, $var2){
return ($var1 + $var2);
}

In the example above I passed var1 and var2 into a function that adds them together and returns the result.

//call this function
$total =myFunction(1,2);

I passed 'hard coded' numbers here but variables could be used also

$a = 1;
$b =2;
$total =myFunction(a,b);

both will return 3 to $total

Edited by JRM: n/a

0

In what context are you referring?
Functions ?

function myFunction($var1, $var2){
return ($var1 + $var2);
}

In the example above I passed var1 and var2 into a function that adds them together and returns the result.

//call this function
$total =myFunction(1,2);

I passed 'hard coded' numbers here but variables could be used also

$a = 1;
$b =2;
$total =myFunction(a,b);

both will return 3 to $total

I'm sorry. I should have been more clear. I meant from one page to another.

0

So you are referring to something like this? <a href="whatever.com?variable=value">Example</a>

There are a lot of reasons, but the main reason I use them is to capture something specific in order to use it later. For example, say you've got a forum like daniweb. Each thread is essentially assigned an id to identify it. If a user is not logged in and tries to reply, they would be redirected to a login page first. But you need to keep track of the thread they were at. So you would pass a variable so the redirection script knows where they were initially to take them back there after log in. This is just one example of course.

Edited by Tekkno: n/a

0

So you are referring to something like this? <a href="whatever.com?variable=value">Example</a>

There are a lot of reasons, but the main reason I use them is to capture something specific in order to use it later. For example, say you've got a forum like daniweb. Each thread is essentially assigned an id to identify it. If a user is not logged in and tries to reply, they would be redirected to a login page first. But you need to keep track of the thread they were at. So you would pass a variable so the redirection script knows where they were initially to take them back there after log in. This is just one example of course.

Nice example. I welcome others with a little code illustration. Thanks everyone.

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.