Showing posts with label PHP Array functions. Show all posts
Showing posts with label PHP Array functions. Show all posts

Friday, October 17, 2008

The str_split() function

This function splits a string into an array of strings.

syntax: str_split(string[,length]);

string – the input string
length – the number of characters each element in the output array must hold. The default value is 1.

Example input:

$str1="This is a simple program number";
print_r(str_split($str1,5));

Example output:

Array ( [0] => This [1] => is a [2] => simpl [3] => e pro [4] => gram [5] => numbe [6] => r )

Monday, September 29, 2008

The implode() function

The implode function is used to glue together elements of an array into a string.

Syntax: implode([separator, ]array);

separator - this parameter specifies the character or characters to be put between the array elements when they are glued together into a string. The default value is an empty space.

array – the input array

Example input:

$employee = array('This', 'is','John.');
echo implode(" ",$employee);

Example output:

This is John.