What is [{ }] notation in php?

Member

by dedrick , in category: PHP General , 10 months ago

What is [{ }] notation in php?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by darrion.kuhn , a month ago

@dedrick 

In PHP, [{ }] notation allows you to create an array with one element, which is itself an empty array. It is a shorthand way of creating a nested array in one line.


For example:

1
2
$arr = [{}];
print_r($arr);


This will output:

1
2
3
4
5
6
Array
(
    [0] => Array
        (
        )
)