Member Avatar for Rahul47

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.

"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

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.