update page now
PHP 8.5.6 Released!

Voting

: two minus two?
(Example: nine)

The Note You're Voting On

marc
2 years ago
If your data is smaller than the expected count with the list expansion:

<?php
$data = "foo:*:1023:1000::/home/foo:/bin/sh";
list($user, $pass, $uid, $gid, $gecos, $home, $shell,$nu) = explode(":", $data);
?>

The result is a warning not an error:

PHP Warning:  Undefined array key 7 in ...

The solution is to pad the array to the expected length:

<?php
$data = "foo:*:1023:1000::/home/foo:/bin/sh";
list($user, $pass, $uid, $gid, $gecos, $home, $shell,$nu) = array_pad( explode(":", $data), 8, ""); 
// where 8 is the count of the list arguments
?>

<< Back to user notes page

To Top