ataria Posted May 3, 2007 Share Posted May 3, 2007 Okay. What I am looking to do is run a variable into a function ( function($variable); ) and then, have it at the end, predefine it in the function. so, the script would look likeeee. $variable = $row[variable]; function($variable); and, then I can use it on the rest of the script as $variable. is that possible, If so, how do i do it? Link to comment https://forums.phpfreaks.com/topic/49900-functions-returning-a-variable/ Share on other sites More sharing options...
ataria Posted May 3, 2007 Author Share Posted May 3, 2007 anyone? Link to comment https://forums.phpfreaks.com/topic/49900-functions-returning-a-variable/#findComment-244830 Share on other sites More sharing options...
john010117 Posted May 3, 2007 Share Posted May 3, 2007 First of all, please wait at least an hour before double posting. We all have lives, you know. Second of all, care to elaborate on your problem? Link to comment https://forums.phpfreaks.com/topic/49900-functions-returning-a-variable/#findComment-244833 Share on other sites More sharing options...
ataria Posted May 3, 2007 Author Share Posted May 3, 2007 Okay. I'll just make a quick little code snippet. <?php // would be the function. function secure_int($variable){ $variable = intval($variable); return $variable; } // would be the script. secure_int($id); echo "Your ID is ".$id."!"; ?> see how I didn't use "$id = function($id);" is that possible? =/ Link to comment https://forums.phpfreaks.com/topic/49900-functions-returning-a-variable/#findComment-244835 Share on other sites More sharing options...
ataria Posted May 4, 2007 Author Share Posted May 4, 2007 .... anyone? Link to comment https://forums.phpfreaks.com/topic/49900-functions-returning-a-variable/#findComment-244915 Share on other sites More sharing options...
lalabored Posted May 4, 2007 Share Posted May 4, 2007 Why don't you want to use $id = function($id)? Link to comment https://forums.phpfreaks.com/topic/49900-functions-returning-a-variable/#findComment-244923 Share on other sites More sharing options...
ToonMariner Posted May 4, 2007 Share Posted May 4, 2007 <?php // would be the function. function secure_int($variable) { return intval($variable); } // would be the script. $id = secure_int($id); echo "Your ID is ".$id."!"; ?> the amazing thing here is that you ave managed to generate a function that does the exact same job as an already avialable built in function AND given it a longer name. if you look at the code you could just do this and get exactly teh same result with a little time saving... <?php echo "Your ID is ". intval($id) ."!"; ?> or (if you use $id more in the script) <?php $id = intval($id); echo "Your ID is ". $id ."!"; ?> Link to comment https://forums.phpfreaks.com/topic/49900-functions-returning-a-variable/#findComment-244925 Share on other sites More sharing options...
trq Posted May 4, 2007 Share Posted May 4, 2007 <?php function secure_int(&$variable){ $variable = intval($variable); } secure_int($id); echo "Your ID is ".$id."!"; ?> Link to comment https://forums.phpfreaks.com/topic/49900-functions-returning-a-variable/#findComment-245027 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.