PHP array_splice

This Comment will be submitted for moderation and will not be accessible to other users until it has been approved.


PHP array_splice is a nice, but not enough used function to limit an array to certain x number. Therefore, for example, there is a string with comma separate values that I want to limit or output to only 10 values. I can explode it from comma. This would also convert it into an array. Once converted, you can array splice it till 10th value and then implode the resultant array.

As an example:


<?php
$string
="string1, string2, ... string100"
printten$string )

function 
printten$string )
{
     
$string explode","$string );
     
array_splice$string10 );
     return 
implode","$string );
}

?>





Post Comment

  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <php>, <python>, <ruby>. Beside the tag style "<foo>" it is also possible to use "[foo]". PHP source code can also be enclosed in <?php ... ?> or <% ... %>.