longree Posted August 11, 2006 Share Posted August 11, 2006 Can anybody tell me how I would echo $test?Inother words, how can I global test out of test()?[code]<?php test(); testtwo(); function test() { $test = "Hello this test is working!"; } function testtwo() { extract($GLOBALS); echo"$test"; } ?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/17228-echo-a-var-that-is-in-a-function-that-has-been-defined-in-another-function/ Share on other sites More sharing options...
ScottRiley Posted August 11, 2006 Share Posted August 11, 2006 Take the inverted commas out for a start. Quote Link to comment https://forums.phpfreaks.com/topic/17228-echo-a-var-that-is-in-a-function-that-has-been-defined-in-another-function/#findComment-73011 Share on other sites More sharing options...
longree Posted August 11, 2006 Author Share Posted August 11, 2006 You and I both know that wouldn't make a difference in this case... Quote Link to comment https://forums.phpfreaks.com/topic/17228-echo-a-var-that-is-in-a-function-that-has-been-defined-in-another-function/#findComment-73015 Share on other sites More sharing options...
ScottRiley Posted August 11, 2006 Share Posted August 11, 2006 Don't you have to define functions before you call them? Quote Link to comment https://forums.phpfreaks.com/topic/17228-echo-a-var-that-is-in-a-function-that-has-been-defined-in-another-function/#findComment-73016 Share on other sites More sharing options...
longree Posted August 11, 2006 Author Share Posted August 11, 2006 Either way works...http://php.net/functions[quote]In PHP 3, functions must be defined before they are referenced. No such requirement exists since PHP 4. Except when a function is conditionally defined such as shown in the two examples below. [/quote]Don't tell me you still use PHP 3 :o??? Quote Link to comment https://forums.phpfreaks.com/topic/17228-echo-a-var-that-is-in-a-function-that-has-been-defined-in-another-function/#findComment-73017 Share on other sites More sharing options...
ScottRiley Posted August 11, 2006 Share Posted August 11, 2006 No lol, I'm very inexperienced with PHP (approaching 2 weeks, tbh), but in most languages I've learned that is the case. Quote Link to comment https://forums.phpfreaks.com/topic/17228-echo-a-var-that-is-in-a-function-that-has-been-defined-in-another-function/#findComment-73020 Share on other sites More sharing options...
longree Posted August 11, 2006 Author Share Posted August 11, 2006 Oh right, - PHP is very useful to know... - It's just nown and then I come up with some new problems... Quote Link to comment https://forums.phpfreaks.com/topic/17228-echo-a-var-that-is-in-a-function-that-has-been-defined-in-another-function/#findComment-73023 Share on other sites More sharing options...
sasa Posted August 11, 2006 Share Posted August 11, 2006 try[code]<?php$test='Bla, bla';echo "1st call testtwo:\n";testtwo();echo "\n-------------\n2nd call testtwo:\n";test();testtwo();function test(){ global $test; $test = "Hello this test is working!";}function testtwo(){ global $test; echo"$test";}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/17228-echo-a-var-that-is-in-a-function-that-has-been-defined-in-another-function/#findComment-73056 Share on other sites More sharing options...
ScottRiley Posted August 11, 2006 Share Posted August 11, 2006 [quote author=longree link=topic=103836.msg413813#msg413813 date=1155296581]Oh right, - PHP is very useful to know... - It's just nown and then I come up with some new problems...[/quote]I agree with that, although I've only been learning it a very short while, I'm already amazed by some of the things it can do, I'm really glad I'm learning it. Quote Link to comment https://forums.phpfreaks.com/topic/17228-echo-a-var-that-is-in-a-function-that-has-been-defined-in-another-function/#findComment-73061 Share on other sites More sharing options...
longree Posted August 11, 2006 Author Share Posted August 11, 2006 arrrr, I didn't know global was an input AND an output function...Thanks for that!Good luck with php scott, cya around! Quote Link to comment https://forums.phpfreaks.com/topic/17228-echo-a-var-that-is-in-a-function-that-has-been-defined-in-another-function/#findComment-73095 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.