September 2017
Intermediate to advanced
244 pages
6h 44m
English
As you can see in the previous example, list() works with an array and assigns to variables in the same order. However, as per PHP7.1, list() now supports keys. As [] is shorthand for list(), [] also supports keys.
Here is an example for the preceding description:
<?php$records = [ ["id" => 7, "name" => 'Haafiz'], ["id" => 8, "name" => 'Ali'],];// list() stylelist("id" => $firstId, "name" => $firstName) = $records[0];// [] style["id" => $firstId, "name" => $firstName] = $records[0];
Here, the ID $firstId will have 7 and $firstName will have Haafiz after the preceding code execution, no matter if either list() style is used or [] style is used.
Read now
Unlock full access