note 30306 deleted from function.explode by bjori
| From: | bjori@php.net | Date: | Mon, 25 Sep 2006 08:14:09 +0000 |
| Subject: | note 30306 deleted from function.explode by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-117611@lists.php.net to get a copy of this message | ||
Note Submitter: dan at boxuk dot com
----
Here's a function I find useful from time to time.... When you're assigning the results of
an explode() to a list(x,y,z) of values, you'll get an error/warning in PHP if your explode()
didn't return the same number of arguments as your list... So you can use the following simple
function to always return the correct number of elements in your array:
<?php
// explodeForce - like explode, but rather than just 'limit' the explosion to
// the number of values, it also ensures that this number of elements are
// present in the output array - v.useful for when assigning an explode
// to a list($a,$b,$c)
function explodeForce($sep, $array, $number_values, $pad = '')
{
return array_pad(explode($sep, $array, $number_values), $number_values, $pad);
}
?>