In the code below, is there a way to get the name of the array from within that same array so it doesn’t have to be typed multiple times?
$awesome_array = array(
'fruit'=>'apple',
'name'=>'awesome_array', // Name of array here
'you_are_an'=>'awesome_array' // Name goes here too
);
That is all.
Its not possible directly. But you can achieve this behavior by defining the name prior to defining the array.
Here is 3 ways to do it. There can be more. But I cant recall any other way right now.
Array name is in a string
Most common way
Pekka reminded me in the comments.
Dynamically collect the name