PHP array_splice
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( $string, 10 );
return implode( ",", $string );
}
?>
Post your Answer