explode() and implode() php arrays

No this isn’t about getting frustrated with PHP and nuking your server, this is a couple of very useful (although hard to remember) array functions.

explode() will take a string and give you an array, splitting that string on the delimiter you give. For example, if you have a list of comma seperated values you will work this as follows:

$monkeys = 'bubbles,charlie,george';
$monkeysArray = explode($monkeys,',');
var_dump($monkeysArray); # shows you the array

There is also an optional third parameter, $limit, which will restrict the number of array elements created.

implode() will do the opposite; pass it an array and the glue and in return you will get a string of each array element joined by the glue:

$monkeysArray = array('bubbles','charlie','george');
$monkeys = implode(' and ',$monkeysArray);
echo $monkeys; # gives you "bubbles and charlie and george"

I can never remember which function is which, so try to imagine that you are “exploding” a string to create an array.

Are you a Developer, Designer or Copy Writer? Or Looking For One?

Click here to see 100s of jobs updated every day that you can complete to earn good money. Also find that programmer, designer or copy writer you have been looking for - advertise and get the best guy for your job - click here to find out more

Leave a Reply

Make $100,000/Month - Every Month!

It Works! We Make Our Customers Millionaires! Act now and get $600 bonus and a Free Money Making Website! - click to get started