Skip to content
Advertisement

Destructuring in php

Is it possible to use javascript like destructuring to create an associative array from variables with variable names as keys in PHP… in javascript I can do

JavaScript

Currently I am stick to repetitive way

JavaScript

Can anyone help, it will save me a whole lot of typing?

Advertisement

Answer

There’s no need to create your own function for this, one already exists:

JavaScript

Ouptut:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement