Home » 2021

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 » 2021

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 » 2021

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 » 2021

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 » 2021

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

Home » 2021

How to Add one or More Items to an Array In JavaScript with push()

JavaScript Add Item to Array with push()

This tutorial will show you how to add items to a JavaScript array with the push() method – with code examples. You don’t want to have to re-declare an array every time you want to change the values in it – so let’s look at how to add items to existing arrays using the push() method. About JavaScript Arrays and Declaring Arrays I’ve covered the best way to declare Arrays in JavaScript in our article here. JavaScript Array push() Method Syntax A method is a function or procedure attached to an object. Calling that object’s … Read more

Home » 2021

How to Randomize/Shuffle an Array in JavaScript [Examples]

JavaScript Randomize Shuffle Array

This article will show you a few ways, both easy and complex, to randomize/shuffle an array in JavaScript. The Quick and Dirty Way to Randomize an Array If you aren’t too concerned about the probabilities involved, this code is a quick way to randomize the contents of an array: // Function to return a shuffled copy of a given array function shuffle(array) { var shuffled = […array]; // Make a copy of the array to be shuffled so that the original is not altered by … Read more

Home » 2021

How to Reverse an Array In JavaScript

JavaScript Reverse Array

This short article will show you how to reverse an array in the JavaScript programming language. 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 – and can be accessed by using that index. As an array is ordered, the position matters. Values within arrays will be processed by loops and other data structures in order – so being able to reverse that order is beneficial. Reversing an … Read more

Home » 2021

PHP: Process Each Item In An Array with array_map() [Examples]

PHP array_map

This article will show you how to process a PHP array using array_map() to run a function on each item in the array. Why use array_map()? Arrays store a sequence of values in a single variable. If you’re storing those values, you probably want to do something with them at some point. Say, for example, you had an array of numbers, and you wanted to calculate the square of each number to be stored in a new array. You could create an empty array, loop through the original array calculating … Read more

Categories PHP

Home » 2021

Rounding Numbers Down with the PHP floor() Function, with Examples

PHP floor()

This short tutorial will cover how to use the PHP floor() function to round numbers DOWN – and provide some code examples. The PHP floor() function rounds a number down (and only down!) to the nearest integer. To round a number up to the nearest integer, use the ceil() function instead. To round a number normally, or for more options when rounding a number, use the round() function. PHP floor() Function Syntax The syntax for the PHP floor() function is as follows: floor($NUMBER) Note that: $NUMBER is the float or integer number you wish to perform the floor() operation on floor() will return a float type number regardless of … Read more

Categories PHP