If the variable $a is equal to 5 and variable $b is equal to character a, what’s the value of $$b? 
the answer to this question is give as 100 can any one please tell me how?

Recommended Answers

All 5 Replies

I did a simple script and found that was not the case.

<?php
$a=5;
$b=$a;
echo $$b;
?>

Found that $$b will be blank because it will search for the variable $5 and it is impossible to make a variable with that name.

If the variable $a is equal to 5 and variable $b is equal to character a, what’s the value of $$b? 
the answer to this question is give as 100 can any one please tell me how?
$a = 5;
$b = 'a';
echo $a;//will ehco 5
echo $b;//will echo a
echo $$b//will echo 5
// $$b = $a since $b has value a

$b=a, not $a

yes i know that, its common php interview question at the basic level.
But it has to be like -

$b = 'a'; 
//and not like below -
$b = a;

check this page it will help to understand it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.