Skip to content

Shorter way to write a Spread Operator in a array for null value #18479

Open
@Ronan-Lenor

Description

@Ronan-Lenor

Description

add a new writing possibility, so that :

$array = [...($var !== null) ? ['key' => $var] : []];

could be shortened to

$array = ['key' ?=> $var];

So , if $var = null; then $array would result to []
and if $var = false; then $array would result to['key' => false]

( same as using an array_merge() + array_filter() )

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions