Category: Software Development
-
Shuffle an associative array with PHP
PHP makes it really easy to randomize the order of an array with the shuffle() function. If you’ve ever used this function on an associative array you know that the array will be randomized, but the keys will be dropped. It takes a bit more work, but you can randomize…
-
Incrementing / Decrementing a String with PHP
In the past, we’ve discussed incrementing and decrementing a variable and incrementing and decrementing a number by another number but did you know that we can also increment and decrement a string? You can use the shorthand operators ++ or — to accomplish this. Please note that you can’t increment…
-
Simple Probability Distribution with PHP
We’ve all been there, trying to juggle two or more things for either split testing or just because you want some variety. This came up recently for me with juggling advertising networks and I wrote some simply code to handle it. The premise is simple, you assign weights to the…
-
The Pitfalls of Using BuySellAds
BuySellAds (BSA) is a platform for selling advertisements on your website. They take a mere 25% cut of sales and offer you a marketplace listing to help you gain exposure to potential advertisers. I love the idea and have attempted to use them on a few occasions. As of this…
-
Incrementing / Decrementing a Number by a Number with PHP
We’ve previously discussed how to simply increment and decrement a variable but that only covered incrementing by a value of 1. What about when you want to increment a variable by 5s? There’s a few different ways this can be accomplished. First, the obvious (albeit far from ideal) using ++…
-
Sorting an associative array by a specific key with PHP
One of PHP’s most powerful data types is the array. It can hold numbers, it can hold letters, it can be sorted, sliced and chunked. Speaking of sorting, when sorting an array the straight forward sorting functions are only for sorting by the keys or by the values. What about…
-
The Complexity of Permalinks and Slugs with User Generated Content
I’m not referring to the complexity of the permalink or slug itself, but the complexity to your code that can be introduced with certain formats, specifcally anything that the user can modify. When I was originally building SceneKids.com I wanted to ensure that the user’s username was always in the…
-
How to convert a CSV file into an array with PHP
Loading CSV files into an array is something that comes up more times than I’d like to admit. Scrubbing mailing lists, loading flat files to a database and various other use cases are out there and fortunately, PHP makes it easy to to do. There are a few ways to…
-
How to Determine if it is Friday the 13th with PHP
It seemed fitting that my post on Friday the 13th would be about Friday the 13th. There are 52 Fridays in 2013, but only 2 of them are the 13th day of the month (September and December). To determine if a Friday is a Friday the 13th, we will need…
-
Building a Number Guessing Game in PHP
Believe it or not, but the last 13 or so posts have all been leading up to this one. Generating random numbers, capturing user input, using colors on the command-line, pluralizing words, and then some are all being utilized in this simple number guessing game. The script itself generates a…