Alex King posted a nice tip I use alot about imploding an array to make a separated string without having to worry about having an extra separator left on the end.
One thing I’ve noticed alot in PHP is people not initializing their variables. I’m not sure why this is but it’s really important to do. Coming from a CF background before PHP I grew very used to doing this with the extremely easy tag. My replacement for this in PHP is to put the following code at the top of my scripts for each variable, especially ones coming from an external source:
$page = isset($_GET[‘page’]) ? $_GET[‘page’] : ‘home’;
So if the variable page is set then place it in the local $page variable otherwise set it to some default. It’s also possible to expand on this and do some other types of data checking right here, for instance:
$id = (isset($_GET['id']) && is_numeric($_GET['id'])) ? $_GET['id'] : 0;<br />
Here we’re checking to see both if $_GET[‘id’] is set and if it is numeric. If it isn’t we set to the default of zero.