DCM Posted October 2, 2010 Share Posted October 2, 2010 Hi i have a function strored in a seperate file (included in my main php page for use), my question is a simple one but i cannot seem to find the answer on the web to this: I call the function as follows passing the variable $name <?php myfunction($name) ?> The function does somehting simple such as: <?php function myfunction ($name) { if ($name = 'bob') { return true; } else return false; } ?> How do i then obtain the true or false value of the function from back with my main php page? Quote Link to comment https://forums.phpfreaks.com/topic/214973-simple-question-on-functions/ Share on other sites More sharing options...
wildteen88 Posted October 2, 2010 Share Posted October 2, 2010 You capture the return value by assigning it a variable $myFuncResult = myfunction($name); Quote Link to comment https://forums.phpfreaks.com/topic/214973-simple-question-on-functions/#findComment-1118262 Share on other sites More sharing options...
DCM Posted October 3, 2010 Author Share Posted October 3, 2010 Thanks the way i did it in the end was to use a session variable that got set by the function. I tried the way you suggested but maybee i was missing something obvious. Quote Link to comment https://forums.phpfreaks.com/topic/214973-simple-question-on-functions/#findComment-1118637 Share on other sites More sharing options...
Yesideez Posted October 3, 2010 Share Posted October 3, 2010 if ($name = 'bob') When you're checking with if() you need to use the double equals like this: if ($name == 'bob') That checks "if equal to". In your original code you were assigning $name to be "bob" and the result of that is true because $name was successfully given the value "bob" Quote Link to comment https://forums.phpfreaks.com/topic/214973-simple-question-on-functions/#findComment-1118663 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.