0

I was going through this book on php and i was left confused what author is trying to convey.

Following is that part.

You must use quotes if you’re using interpolation to build the array index:
$age["Clone$number"]
However, don’t quote the key if you’re interpolating an array lookup:
// these are wrong
print "Hello, $person['name']";
print "Hello, $person["name"]";
// this is right
print "Hello, $person[name]";

My question is:
1) What is interpolation to build array index?

Thanks.

2
Contributors
1
Reply
18
Views
4 Years
Discussion Span
Last Post by arunmagar
0

"interpolation to build the array index"
By this sentense I think author may be trying to say that he is forming a index value using variable $number.

$age["Clone$number"]

He is joing string "Clone" and value from variable $number to form new more index value like
$age[Clone1]
$age[Clone2]
$age[Clone3]
That is interpolation.
Here we do not know the value of $number which can be dynamin (anything)

And If we dont use quotes in that , it will throw error.

Please refer Variable_interpolation

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.