I have a line like this in my code:
list($user_id, $name, $limit, $remaining, $reset) = explode(\'|\', $user);
The last 3 parameters may or
list($user_id, $name, $limit, $remaining, $reset)
= array_pad(explode('|', $user), 5, null);
Just add some spare pipes to the end of the string:
list($user_id, $name, $limit, $remaining, $reset) = explode('|', $user.'||||');
problem solved.
Note: If you're loading arbitrary pipe-delimited data, you might want to use str_getcsv() function rather than explode()
.
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);