Check if a variable has been set with the name of the value of another variable
I am setting up a template system, Long story short: I need/want to check if a variable with the name of a tag has been set. the tag name is in another variable.
Therefore, I need to check to see if the content of $tag (i.e. title) has a variable with the same name ($title
).
Any help is appreciated. Thanks.
Use variable variables:
<?php
$tag = 'title';
// bool(false)
var_dump(isset($$tag));
$title = 'this is the title';
// bool(true)
var_dump(isset($$tag));
精彩评论