Home » Articles by: Brad Morton

How to Compare Dates in PHP, With Examples

PHP Compare Dates

This tutorial will show you the best way to compare dates in the PHP programming language – and provide code examples. It’s essential to be able to accurately compare dates when building your app. For example, you may wish to compare dates for reporting purposes – retrieving a list of transactions from a shop for a given reporting period, or you may want to have your user enter a fake birthday into your webpage so that they can pretend that they are over 18. Anyway, … Read more

Categories PHP

Home » Articles by: Brad Morton

Using the PHP ‘exit’ (AKA ‘die’) Function to Terminate your Script [Examples]

PHP exit die

This short article will explain the PHP exit function and how it is used to quit/exit/terminate a PHP script. PHP exit Function Syntax The syntax for the PHP exit function is as follows: exit(STATUS) Note that: exit will terminate the execution of the script at the point it is called STATUS is an optional integer or string value containing a status code or exit message If an integer value with a status code, the script will return this code as the exit status if running on the command line Exit status should be 0 for … Read more

Categories PHP

Home » Articles by: Brad Morton

How to Convert String to Date in JavaScript, With Examples

JavaScript String to Date

Here are some easy-to-understand methods for converting strings to date objects in the JavaScript Programming language. Looking to compare dates in JavaScript? Find out how here. The Hard Way – Using Vanilla JavaScript JavaScript contains built-in functions for parsing a date from a string – but it’s severely limited. So here it is in action: var myString = ’01 Jan 1970 00:00:00 GMT’; var myDate = new Date(Date.parse(myString)); What’s happening here? A string is defined containing a date. A new Date object is then defined using the … Read more

Home » Articles by: Brad Morton

Checking for Inequality in Python: ‘!=’ vs ‘is not’ [Examples]

Python Not Equal

Should you use the != operator or the ‘is not’ statement when comparing values in Python? Read on to find out! The != Comparison Operator The != operator can be used to compare two variables or statements’ return values. If they are not equal, the statement will return TRUE. Python is forgiving when it comes to comparing variables of different types. So if the type of the variables being compared is different, but the value is the same, it will return TRUE (rather than throwing an error) as they are not equal in both type and value. myNumber … Read more

Home » Articles by: Brad Morton

How to Use the PHP *strstr()* Function to Search a String

PHP strstr()

This tutorial will show you how to use the PHP strstr() function to search and return a portion of a string, with examples. What is the strstr() Function For? The strstr() function searches a string and returns the matching portion of the string and everything that follows or precedes it. If the string does not contain a match for the search, a value of false is returned. It’s a hard one to visualize – the examples below will show you precisely what this means. If you’re simply looking to confirm whether … Read more

Categories PHP

Home » Articles by: Brad Morton

How to Round Numbers (Integer, Decimals) in PHP with the round() Function

PHP round()

This article will show you how to round numbers in PHP with the round() function, including rounding to the nearest integer or a set number of decimal places. Why Round Numbers? There are various reasons you may want to round numbers. You don’t need incredible accuracy for many day-to-day calculations. You probably don’t need to know your height to several thousandths of a centimeter if converting from feet – knowing to the nearest whole centimeter is perhaps enough. If you’re calculating tax, you only need to know … Read more

Categories PHP

Home » Articles by: Brad Morton

Implementing a Queue Data Structure in JavaScript [Examples]

JavaScript Queue

A queue is a commonly used data structure in programming. Here’s how to implement and use a queue in JavaScript. JavaScript doesn’t include a data structure specifically called a queue – but that doesn’t mean the functionality isn’t there. JavaScript arrays can be used in the same way – it’s just the terminology that’s a bit different. Rather than duplicating array functionality for queues, queue functionality exists in the array functions of JavaScript. What is a Queue Data Structure? A queue is a sequence of items in a specific order. Items can be enqueued (added … Read more

Home » Articles by: Brad Morton

Rasperry Pi RetroPie Emulation Station Install Walkthrough (Video Games on Pi)

retropie video game emulation raspberry pi

This guide will walk you through the installation and configuration of RetroPie (a Linux distribution with Emulation Station pre-configured) and where to source some legal retro game console ROMS. RetroPie is a ready-to-use Linux OS for your Raspberry Pi, which has everything already configured and ready to emulate NES, SNES, GameBoy, Nintendo 64, Playstation, Sega, and many other game consoles. The installation and configuration steps are super easy.  I’ve documented them below with screenshots and notes.  Once RetroPie is up and running, I’ll install a … Read more

Home » Articles by: Brad Morton

The Best Way to Declare an Array in JavaScript

JavaScript Declare Array

There are several ways to declare an array in JavaScript. This article will show you which is the best. What is an Array? An array is a type of variable that holds an ordered list of values. Each value has a position in the array, called the index. The index can be used to access each value in the array. Indexes are integer values, which start counting from 0 (zero) for the first item in the array. The Literal Constructor – Declaring an Array using Square Brackets (The Best … Read more

Home » Articles by: Brad Morton

Merge Arrays in JavaScript with concat() and push() [Examples]

JavaScript Join Merge Concatenate Arrays

This tutorial will show you the correct ways to merge two or more arrays in JavaScript with the concat method – and provide a warning about how not to merge arrays. Merging/Joining Arrays in JavaScript with the concat()* Method The concat() method exists with one purpose – to merge arrays. concat() Method Syntax array.concat(ARRAYS) Note that: array is the first array of the arrays to be joined ARRAYS should be a comma-separated list of arrays to be added to the first array They will be joined in the order of appearance concat() returns a new array – … Read more