This question might be a duplicate of why in array single quotes not required according to the syntax
but I didn't the explanation I need over there. We know we can do echo "$myArr[0]"
, but we can't do the same with associative arrays like echo "myAssocArr['myKey']"
. I know we can use php complex syntax to get around, like echo "{myAssocArr['myKey']}"
.
My question is, if php can access normal index arrays without complex syntax, then why can't it access accosiative arrays' values as well. What is happening inside php compiler/zend/whatever engine that prevents it from accessing assosiative arrays' values in a string without the complex syntax.
'; $arr = [ 'mykey' => 'key in array.', ]; echo "$arr[mykey]";``` It is different with constant. What I get from `echo "$arr[mykey]";` is **key in array.** NOT **My key** from constant. – vee Nov 27 '21 at 19:02