Say I have a function that returns an array like this...
array(
0 => 'jpg',
1 => 400,
2 => 500
);
I want the indexes 1 and 2 only, and I want them as local variables. I don't care about 0.
I could do...
list($throwaway, $width, $height) = getImageDetails($imagePath);
unset($throwaway);
...but obviously that is very ugly.
I tried placing NULL
there, but I got the scope resolution error.
Is there a clean way to skip an array index using PHP's list()
?
Yep, don't populate that argument, this is perfectly valid:
list(, $width, $height) = getImageDetails($imagePath);
(see also Example 1 in the manual)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With