Q&A

Q1: Apart from the global keyword, is there any way that a function can access and change global variables?
A1: You can also access global variables anywhere in your scripts with a built-in associative array called $GLOBALS. To access a global variable called $test within a function, you could reference it as $GLOBALS['test'] You can learn more about associative arrays in the next hour.

You can also change global variables from within a function if it has been passed in by reference.

Q2: Can you include a function call within a string, as you can with a variable?
A2: No. You must call functions outside quotation marks.

Get Sams Teach Yourself PHP in 24 Hours, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.