It often happens that i use some function or method that returns an array of elements, but i need just the first one. Assigning this first element to variable is usually done in two lines, for example:
$arr = explode(".", "zxc.vbn.asd"); $first = $arr[0]; // $first = "zxc"
With the help of function list() it can be narrowed down to just one line:
list($first) = explode(".", "zxc.vbn.asd"); // $first = "zxc"
In my opinion that’s a neat solution for common problem, saves just a one line (and some memory), yet judging by the number of times we do “such thing” in the project i think you will find this helpful.


2 Comments on "PHP list quick tip"
You can use strtok function for this purpose.
Example:
$first = strtok( “zxc.vbn.asd” , “.” );
Yes, but only in this example.