Fizz Buzz in PHP

Fizz buzz is a fairly common screening question to help sniff out non-programmers during the interview process. The task is to print out numbers 1 through 100 but for multiples of 3 print out “Fizz” instead of the number and for multiples of 5 print “Buzz” instead. If the number happens to be divisble by both 3 and 5 print out “FizzBuzz” instead of...

Read Full Article →

How to execute an HTTP POST using PHP cURL

I’ve been doing a lot of API integration recently and cURL ends up being exceptionally handy when you are POSTing to an endpoint. Fortunately using cURL in PHP is really easy: // Sets our destination URL $endpoint_url = 'https://somesite.com/path/to/endpoint'; // Creates our data array that we want to post to the endpoint $data_to_post = [ 'field1' => 'foo', 'field2' => 'bar', 'field3' => 'spam',...

Read Full Article →

Looping through a date range

Looping through a date range isn’t as simple as looping through an array with foreach but it doesn’t take much additional code to get the job done. To loop through a date range you will need to use a loop (I prefer a while loop) and increment the date by using strtotime. I’ll convert the timestamp back to a human readable date as well...

Read Full Article →

Difference between break; and continue;

The topic of break and continue came up the other day and I thought it would make for a good blog post. You’re probably familiar with break moreso than continue because it is part of a switch statement’s syntax. Both break and continue can also be used inside of looping statements like while, for and foreach. According to php.net continue can also be used...

Read Full Article →

PHP without fancy braces

PHP is a C-style language and thus uses fancy braces to wrap or hug control structures. PHP is also a language that is extremely flexible so you can also get by without using fancy braces. You will never get away from them entirely as functions and classes / class methods must have fancy braces and currently do not offer an alternative syntax. Let’s take...

Read Full Article →