PHP List Function Silently Failing? Solution

If you use PHP’s list function to quickly extract array values out into dollar variables then you might have an issue where it just doesn’t work for some reason.

The problem is that list only works with numeric arrays. If you are using an associative array (with strings for keys instead of numbers) then list will not work.

There is any easy solution though, simply change:

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

To:

$array = array('a'=>1, 'b'=>2, 'c'=>3);
list($a, $b, $c) = array_values($array);

And it will work as you expect.