0
In which cases a "Variable Variable" will be useful?
I understand how it works but can't imagine when or why I will use it. Thanks for your answers!
2 Answers
0
Refer here for an example http://www.dummies.com/programming/php/how-to-use-php-variable-variables/
0
Since PHP is often used to process form data (like capturing a user's name and then storing it in a database), it becomes essential to use and be comfortable with variables.
Variables are perfect for dealing with the unknown, like pulling in information from a database, or capturing information from a JSON file or XML data. You want to pull information and process it, but you don't know what that information will be.
I use variables ALL the time when doing WordPress themes. Here are a few PHP examples of variables that I have used in working code:
$author = get_the_author();
$pfx_date = get_the_date( $format, $post_id );
$categories = get_categories();
$author lets me display the author of a current blog post without knowing who it is.
$pfx_date lets me get the date of the current blog post without knowing when it was published
$categories lets me display each of the categories that the current blog post belongs to without knowing what they are