SitePoint Sponsor |
|
User Tag List
Results 1 to 3 of 3
Thread: function in variable
-
Mar 30, 2005, 21:02 #1
- Join Date
- Aug 2003
- Location
- Antwerp, Flanders, BE , EU
- Posts
- 166
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
function in variable
Prolly an absolute newbie question, but how do I trigger a function as this one (which should take the name of a variable and then add "-en" to it):
PHP Code:function trans_var($var){
$temp = explode(".",$var);
$temp[count($temp)-2] .= "_en";
print(implode(".",$temp));
}
PHP Code:<?php echo($news["message"]);?>
PHP Code:<?php print($news[trans_var('message')]);?>
How can I do this?
-
Mar 30, 2005, 21:11 #2
- Join Date
- Nov 2004
- Location
- San Diego, CA (USA)
- Posts
- 126
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
fix your function to this:
PHP Code:function trans_var(&$var){
$temp = explode(".",$var);
$temp[count($temp)-2] .= "_en";
return implode(".",$temp);
}
PHP Code:print trans_var($news['message']);
-
Mar 31, 2005, 02:04 #3
- Join Date
- Feb 2005
- Location
- Chester, Cheshire
- Posts
- 565
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
a little tip i was given a while ago - try and avoid printing from functions, echo'ing is generally ok but either way i would avoid printing inside a function. store the values in a variable and return them as shown above... then print out the result of the function.
Bookmarks