Is it possible in PHP to reference an array index on creation of the array?
For example, I need to create a list that will only be used once, in this case to map a word to an index. I know this can be done in Perl, and I think Javascript but can't get it to work in PHP.
$fruit = 2;
$fruitName = ( array( "Apple", "Pear", "Banana", "Kiwi"))[$fruit];
echo $fruitName;
This should output Banana, is this possible or do I have to create the array first?
I realise that I'm just being lazy trying to shortcut it, and I also realise that this post is 7 lines so could have done this 7 times already in the time it took to ask lol
()this should be$fruitName = array( "Apple", "Pear", "Banana", "Kiwi")[$fruit];