Parallel array assignment in PHP Parallel array assignment in PHP arrays arrays

Parallel array assignment in PHP


Use list

$arr = array(1,2,3);list($a, $b, $c) = $arr;


As of PHP 7.1 you can use the list shorthand [] for array destructuring.

[$a, $b, $c] = [1, 2, 3];

Also as of 7.1 you can destructure non-numerically keyed arrays similar to the way that object destructuring works in ES6. https://stitcher.io/blog/array-destructuring-with-list-in-php