0

Is it possible to check if a variable exist using a variable value? Like

//some variables:
$variable_a;
$variable_b;
$variable_c;
$variable_d;

$variable = '$variable_b';
     if (the content $variable which is '$variable_b' exists == true){
    
}

or how to make a variable value into a variable? Like

$variable = 'variable_name'; ...some code to make 'variable_name' a variable

4
  • Can you explain a bit more? Not sure I understand. Commented Feb 23, 2022 at 8:01
  • Does this answer your question? Check if a variable is undefined in PHP Commented Feb 23, 2022 at 8:09
  • More specifically, check this there. We also expect you to do some Google search before asking. Commented Feb 23, 2022 at 8:10
  • @nice_dev I'm not talking about isset() because I think it checks the variable itself instead of the variable value. Not really sure though Commented Feb 23, 2022 at 8:18

1 Answer 1

0

You can use variable variables in PHP, and then check if such a variable has a value. For instance:

$variableA = 'Hello';
$variableB = 'variableA';
echo ${$variableB};

returns Hello on your screen. You can also check if $variableA has a value by doing:

if (isset(${$variableB})) {
    ....
}

Note that in your question you have variables that have no value, they are not set. The whole purpose of variables is to have a value, hence their name, so your variables are some kind of zombies, not really alive, not really dead. They are not set, so isset() will return false.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.