WhiteCube Posted December 10, 2007 Share Posted December 10, 2007 hi all! I've got this php script here.. but it doesn't seem to work when in a function! <?php $username = "sss"; $exe = "users"; $exe(); function users() { echo "username=$username"; } ?> While reading this.. it should echo out.. "username=ssss".. right? But I keep getting "username=" just that!! Can someone tell me what's going on? Thanks! Link to comment https://forums.phpfreaks.com/topic/80982-solved-echo-not-working-properly-in-functions/ Share on other sites More sharing options...
rajivgonsalves Posted December 10, 2007 Share Posted December 10, 2007 make $username global in your function function users() { global $username; ... Link to comment https://forums.phpfreaks.com/topic/80982-solved-echo-not-working-properly-in-functions/#findComment-410839 Share on other sites More sharing options...
WhiteCube Posted December 10, 2007 Author Share Posted December 10, 2007 ;D Thanks man! Your the greatest!! Link to comment https://forums.phpfreaks.com/topic/80982-solved-echo-not-working-properly-in-functions/#findComment-410841 Share on other sites More sharing options...
Mad Mick Posted December 10, 2007 Share Posted December 10, 2007 Or change the function so it takes a parameter: function users ($name){ echo "username=$name"; } then use: $exe($username); Link to comment https://forums.phpfreaks.com/topic/80982-solved-echo-not-working-properly-in-functions/#findComment-410862 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.