Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a clean way to *skip* an array index using PHP's `list()`?

Tags:

php

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()?

like image 547
alex Avatar asked Jan 25 '11 00:01

alex


1 Answers

Yep, don't populate that argument, this is perfectly valid:

list(, $width, $height) = getImageDetails($imagePath);

(see also Example 1 in the manual)

like image 89
Mark Elliot Avatar answered Oct 27 '22 03:10

Mark Elliot