Elements combination of same array in PHP -


in project, have receive string user (in textarea). string converted array. problem that, character length must minimum of 3, in following array next element should joined current 1 if character length less 3. how perform in php.

a[0]=>this a[1]=>is a[2]=>an a[3]=>example a[4]=>array. 

output should be:

a[0]=>this a[1]=>isan a[2]=>example a[3]=>array. 

just try with:

$input  = ['this', 'is', 'an', 'example', 'array.']; $output = [];  $part = ''; foreach ($input $value) {     $part .= $value;     if (strlen($part) > 3) {         $output[] = $part;         $part = '';     } } 

output:

array (size=4)   0 => string 'this' (length=4)   1 => string 'isan' (length=4)   2 => string 'example' (length=7)   3 => string 'array.' (length=6) 

Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -