Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Ronan-Lenor opened this issue May 1, 2025 · 0 comments
Open

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

Ronan-Lenor opened this issue May 1, 2025 · 0 comments

Comments

@Ronan-Lenor
Copy link

Ronan-Lenor commented May 1, 2025

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() )

@Ronan-Lenor Ronan-Lenor changed the title Shorter way to write a Spread operator in a array for null value Shorter way to write a Spread Operator in a array for null value May 1, 2025
@Ronan-Lenor Ronan-Lenor changed the title Shorter way to write a Spread Operator in a array for null value Shorter way to write a Spread Operator in an associative array for null value May 1, 2025
@Ronan-Lenor Ronan-Lenor changed the title Shorter way to write a Spread Operator in an associative array for null value Shorter way to write a Spread Operator in a array for null value May 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants