Home » Articles by: Brad Morton

How to Sort Arrays in JavaScript with the sort() Method [Examples]

Javascript Sort Array

This tutorial will show you how to sort arrays in the JavaScript programming language with the array sort() method and provide some code examples. What is an Array in JavaScript? An array is a type of JavaScript variable that can hold a series of variables, references to variables, or values. It’s like a list of items. Each item or element in the array has a value and a position. The position is the order the element appears in the array and is called the index. Indexes are zero-indexed – meaning … Read more

Home » Articles by: Brad Morton

How to Generate a Range (Numbers/Letters) in JavaScript

JavaScript Generate Range

This article will show you how to generate a range of numbers or letters in JavaScript, and provide some functions you can copy and paste into your own project. The Python, PHP, and many other popular programming languages provide a range() function, for generating a range of numbers or letters between two values. JavaScript does not have a built-in function for doing this, but it’s easy functionality to implement yourself. Here’s how to do it, and some pre-made functions you can just paste into your own project to use … Read more

Home » Articles by: Brad Morton

Copy/Clone an Array or Object in JavaScript The Right Way [Examples]

How to Copy/Clone JavaScript Array

This tutorial will show you how to properly copy/clone an array or object in JavaScript – it’s not as simple as it seems! Copying an array or object may seem simple – but JavaScript throws a spanner in the works – the fact that when you assign the value of one variable to another it references the original variable. This means that if the value of the original variable is changed, the value of the copy will change too! To get around this, you will need to clone the array – ensuring … Read more

Home » Articles by: Brad Morton

Exiting JavaScript Loops: ‘break’ & ‘continue’ [Examples]

Javascript Break Continue Statements

This article will explain the JavaScript break and continue statements and how they are used to exit and skip iterations in loops. JavaScript Loops In programming, a loop iterates through a series of values, performing an action on each value it encounters. Arrays can be looped through using the forEach method, and the for statement can be used to loop through a set of values generated by a JavaScript expression. You may encounter situations where you want to prematurely exit a loop, or skip processing certain values in the loop. This is what … Read more

Home » Articles by: Brad Morton

Searching JavaScript Arrays with the Array.find() Method [Examples]

Javascript Array find()

This tutorial will show you how to search arrays in JavaScript using the Array.find() method, and show some code examples. JavaScript Arrays An array is a type of variable that holds an ordered list of values (or references to other variables), called array elements. Each element has a position in the array, called the index – and can be accessed by using that index. We’ve got a whole pile of things you can do with JavaScript arrays. Accessing elements in the array by their index is convenient, … Read more

Home » Articles by: Brad Morton

How to Write/Save to a File with PHP [Examples]

PHP Write/Save File

This tutorial will demonstrate how to write data to a file on the server in the PHP programming language. Code examples are provided to show you how it’s done. Writing data to a file server-side is a common task. Whether you’re writing log files so you can debug your app, or saving user submitted data, you will need to save a file at some point in your web development career. Writing data to a file in PHP is a three-step process. You must first open … Read more

Categories PHP

Home » Articles by: Brad Morton

Ultimate Guide to Uploading Multiple Files With PHP [Examples]

PHP Multiple File Uploads Ultimate Guide

This tutorial will explain how to upload one or multiple files from the web browser to the server using PHP. Code examples are included, including the code for limiting file size and type. Being able to have your users upload files to your app has become expected functionality in most web apps. Photos, filled out PDF forms, videos, recordings – any kind of file can be uploaded, and the process is relatively straight forward. PHP provides all of the required tools for file uploading and … Read more

Categories PHP

Home » Articles by: Brad Morton

How to Resize/Crop Images in PHP with the GD Library

PHP Resize/Crop Image

This tutorial will show you how to resize or crop images in the PHP programming language. Code examples are provided which can be copy and pasted into your project. GD Library vs ImageMagick Image resizing in PHP is performed by an optional image processing library. The two most popular image processing libraries for PHP are GD and ImageMagick. Both work well, but I’ll be sticking to the GD Library for this tutorial as it is the most popular and supported. Installing the GD PHP Extension The GD library … Read more

Categories PHP

Home » Articles by: Brad Morton

Multidimensional/Nested Arrays in JavaScript [Guide]

Multidimensional/Nested Arrays in JavaScript

This guide aims to succinctly show you how multidimensional arrays can be created and used in the JavaScript programming language. What are Arrays? Arrays are a key component in any app kind of app you may wish to build – arrays allow you to store an ordered list of variables or values of any length in a single variable – ready to be iterated over, displayed, or otherwise processed. For example, an array could contain a list of contacts for an instant messaging application, or … Read more

Home » Articles by: Brad Morton

How to Rename Files & Directories in PHP [Examples]

PHP Rename File

This tutorial will show you to rename files and folders in PHP with the rename() function – including some code examples you can use in your own project. We’ve already covered uploading files and deleting files in PHP, read on to find out how to rename them. rename() PHP Function Syntax The syntax for the rename() function used to delete files in PHP is as follows: rename($FROM, $TO, $CONTEXT) Note that: $FROM is the path of the existing file you wish to rename $TO is the new path you wish to rename … Read more

Categories PHP