A few helpful string and array PHP functions

iD Tech in action

I've been working a great deal with vBulletin, our forums system, and in doing so have had to brush on my PHP. Through the course of preparing the system for the summer I've come across a few PHP functions that I was not aware. Here's a few that you may not know about:

implode: takes an array of strings and concatenates them, using $glue as a separator.

Example: string implode (string $glue, array $pieces)
$before = array('one', 'two', 'three');
$after = implode(",", $before);
echo $after;

Produces:one,two,three

explode: does the exact opposite of implode - it takes a delimiter separated string and transforms it into an array.

Example: array explode (string $delimiter, string $string [, int $limit= -1])
$before = "one,two,three";
$after = explode(",", $before);
var_dump $after;

Produces:
array('one', 'two', 'three')

var_dump: unlike a typical echo, which will just print "Array" for arrays, var_dump will traverse and print the contents of the array.

Example: void var_dump (mixed $expression [, mixed $expression [, $... ]])
$before = "one,two,three";
var_dump $before;

Produces:
array(3) {
[0]=>string(1) "one"
[1]=>string(1) "two"
[2]=>string(1) "three"
}

Of course, if you use PHP any more than casually then you already know these functions. But if you frequently jump around among web technologies you might find these useful.

A photo of Ryan

Ryan manages blog content at iD, starting with the company in 2008. He earned his MBA from Santa Clara University after obtaining his Bachelor’s degree from Arizona State. In terms of interests, Ryan possesses a fanatical addiction to Oakland A’s baseball, a borderline obsession with the music of John Mayer, and an undying commitment to Buffalo wings (and really anything else advertised as having Buffalo wing-flavoring).
Connect on LinkedIn!

Featured Posts

Authors

About iD Tech

iD Tech is the #1 tech camp on the planet, with 150+ locations nationwide. Kids and teens learn to code, design video games, produce videos, mod Minecraft, create with Roblox, engineer robots, model and print 3D characters, work with AI and machine learning, build laptops, learn about cybersecurity, and more!

We've bet our reputation on recruiting the top instructors in the country. Our 8:1 student-to-instructor average ensures customized learning with the smallest class sizes, leading to "a-ha moments" and awesome outcomes.

View all locations

View all courses