SitePoint Sponsor |
|
User Tag List
Results 1 to 5 of 5
-
Apr 4, 2009, 20:16 #1
Passing a function variable to another function
Hey guys.
I hope I can reply if someone is able to answer me, my dad might turn off the internet in a little bit.
I was wondering this.
is there a way to do that and pass the hey() variable into the say()?
PHP Code:function hey () {
$hey = '1';
}
function say() {
echo hey() . ' test';
}
I own a php manual but can not solve this.
Thank you
-
Apr 4, 2009, 20:37 #2
- Join Date
- Jul 2005
- Location
- Orlando
- Posts
- 634
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
return is what you're looking for.
PHP Code:function hey () {
$hey = '1';
return $hey;
}
function say() {
echo hey() . ' test';
}
-
Apr 4, 2009, 20:41 #3
- Join Date
- Jul 2008
- Posts
- 213
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
You have to call say() so it can call hey(), and yes use return in hey().
-
Apr 4, 2009, 20:52 #4
PHP 5.3 Coolness
PHP Code:function hey () {
$hey = '1';
return function () use ( $hey ) {
echo $hey, ' test';
};
};
$say = hey();
$say();
-
Apr 4, 2009, 22:06 #5
Ok I understand thank you for this reply guys, i can play with this more and understand thing now thanks
ps: that 5.3 php is very cool
Bookmarks