I have a line like this in my code:
list($user_id, $name, $limit, $remaining, $reset) = explode('|', $user);
The last 3 parameters may or may not be there. Is there a function similar to list that will automatically ignore those last parameters if the array is smaller than expected?
list($user_id, $name, $limit, $remaining, $reset)
= array_pad(explode('|', $user), 5, null);
If you're concerned that SDC's solution feels "hacky"; then you can set some default values and use:
$user = '3|username';
$defaults = array(NULL, NULL, 10, 5, FALSE);
list($user_id, $name, $limit, $remaining, $reset) = explode('|', $user) + $defaults;
var_dump($user_id, $name, $limit, $remaining, $reset);
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