fesan Posted November 24, 2012 Share Posted November 24, 2012 Happy Saturday. Can someone explain why this code returns nothing? function test(){ $test = "test"; } test(); echo $test;} Link to comment https://forums.phpfreaks.com/topic/271104-functions/ Share on other sites More sharing options...
Barand Posted November 24, 2012 Share Posted November 24, 2012 because variables are local to functions. You need function test(){ $test = "test"; return $test; } echo $test(); Link to comment https://forums.phpfreaks.com/topic/271104-functions/#findComment-1394744 Share on other sites More sharing options...
fesan Posted November 24, 2012 Author Share Posted November 24, 2012 ahh... Thanks. And if there are allot of variables i need to get out of the function? Do i have to return them all? Link to comment https://forums.phpfreaks.com/topic/271104-functions/#findComment-1394746 Share on other sites More sharing options...
Pikachu2000 Posted November 24, 2012 Share Posted November 24, 2012 Multiple values are usually easiest to return in an array. Link to comment https://forums.phpfreaks.com/topic/271104-functions/#findComment-1394748 Share on other sites More sharing options...
50r Posted November 24, 2012 Share Posted November 24, 2012 function test(){ $test = "test"; $foo ="me"; $boo ="we"; return array($test,$foo,$boo); } $array = test(); then go ahead and use the valuable from the array. Link to comment https://forums.phpfreaks.com/topic/271104-functions/#findComment-1394763 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.