• Skip to main content
  • Skip to primary sidebar
  • Skip to footer

Matt Doyle | Elated Communications

Web and WordPress Development

  • About Me
  • Blog
    • Design & Multimedia
      • Photoshop
      • Paint Shop Pro
      • Video & Audio
    • Online Marketing
      • E-Commerce
      • Social Media
    • Running a Website
      • WordPress
      • Apache
      • UNIX and Linux
      • Using FTP
    • Web Development
      • HTML
      • CSS
      • JavaScript
      • PHP
      • Perl and CGI Scripting
  • Portfolio
  • Contact Me
  • Hire Me
Home / Blog / Web Development / PHP / PHP Arrays

PHP Arrays

These articles explain how arrays work in PHP, and show how to create and manipulate arrays.

Easy Ways to Sort Arrays in PHP

16 August 2010 / 2 Comments

Easy Ways to Sort Arrays in PHP

As I mentioned in my earlier article, Creating Arrays in PHP, arrays are very useful if you need to store and manipulate a large amount of data in one go. One useful way you can manipulate this data is to sort it in a particular order.

PHP gives you a large number of sorting functions that can sort arrays using many different criteria. For example, you can sort in ascending or descending order, by key, or by value. These functions make it really easy to sort arrays without getting bogged down in the details of sort algorithms.

We won’t try to cover every single PHP array-sorting function in this tutorial. Instead, you’ll learn about the functions that you’re likely to find the most useful in your everyday coding.

Let’s get started!

[Read more…] about Easy Ways to Sort Arrays in PHP

Using Multidimensional Arrays in PHP

19 July 2010 / 16 Comments

Using Multidimensional Arrays in PHP

Array elements in PHP can hold values of any type, such as numbers, strings and objects. They can also hold other arrays, which means you can create multidimensional, or nested, arrays.

In this tutorial you learn how to create multidimensional arrays, how to access elements in a multidimensional array, and how to loop through multidimensional arrays.

[Read more…] about Using Multidimensional Arrays in PHP

Using foreach to Loop Through PHP Arrays

27 May 2010 / 2 Comments

Using foreach to Loop Through PHP Arrays

Often you need to move through all the elements in a PHP array so that you can do something with each element’s value. For example, you may want to display each value in an HTML table, or give each element a new value.

In Counting PHP Array Elements Using count(), I showed how you can use a for loop along with the count() function to loop through an array. However, there’s a much easier way to loop through arrays: the foreach construct.

In this article you learn the basic syntax of foreach, and see how to use it to loop through both indexed and associative arrays.

[Read more…] about Using foreach to Loop Through PHP Arrays

Counting PHP Array Elements Using count()

6 May 2010 / Leave a Comment

Counting PHP Array Elements Using count()

Often it’s useful to know how many elements an array contains. Here are some common reasons for counting the number of elements in an array:

  • You can then use a for loop to move through the elements
  • You can display the total number of elements to the user (such as the number of search results returned)
  • You can calculate the average of the values in the array (in conjunction with array_sum())

PHP makes it easy to count array elements, thanks to its built-in count() function. In this tutorial you’ll learn how to use count() to count the elements in both regular and multidimensional arrays, and how to move through all the elements of an indexed array by using count() and a for loop.

[Read more…] about Counting PHP Array Elements Using count()

Extracting Elements from PHP Arrays with array_slice()

30 March 2010 / Leave a Comment

In Working With Array Elements in PHP, you saw how to read and change individual elements within a PHP array. However, sometimes it’s useful to work with a range of array elements. For example, you may want to work with a large array in chunks, or sort an array then retrieve just the “top 10” values from the start of the array.

In this tutorial you’ll explore PHP’s array_slice() function for extracting a range of elements from an array.

[Read more…] about Extracting Elements from PHP Arrays with array_slice()

Working With Array Elements in PHP

19 March 2010 / 2 Comments

In Creating Arrays in PHP, you learned how PHP arrays work, and saw how to create an array using PHP.

In this article you take things further, and look at how to access the individual elements inside a PHP array. You’ll see how to:

  • Read element values
  • Alter element values
  • Add and remove elements in an array
  • Output the entire contents of an array

[Read more…] about Working With Array Elements in PHP

Creating Arrays in PHP

10 March 2010 / 3 Comments

Like most programming languages, PHP lets you create arrays. An array is a special type of variable that can hold many values at once, all accessible via a single variable name. Arrays are very useful whenever you need to work with large amounts of data — such as records from a database — or group related data together.

In this article, you’ll:

  • Learn how PHP arrays work, and why they’re useful
  • Look at the difference between indexed arrays and associative arrays, and
  • Learn how to create arrays within your PHP scripts.

[Read more…] about Creating Arrays in PHP

Primary Sidebar

Hire Matt!

Matt Doyle headshot

Need a little help with your website? I have over 20 years of web development experience under my belt. Let’s chat!

Matt Doyle - Codeable Expert Certificate

Hire Me Today

Call Me: +61 2 8006 0622

Stay in Touch!

Subscribe to get a quick email whenever I add new articles, free goodies, or special offers. I won’t spam you.

Subscribe

Recent Posts

  • Make a Rotatable 3D Product Boxshot with Three.js
  • Speed Up Your WordPress Website: 11 Simple Steps to a Faster Site
  • Reboot!
  • Wordfence Tutorial: How to Keep Your WordPress Site Safe from Hackers
  • How to Make Awesome-Looking Images for Your Website

Footer

Contact Matt

  • Email Me
  • Call Me: +61 2 8006 0622

Follow Matt

  • E-mail
  • Facebook
  • GitHub
  • LinkedIn
  • Twitter

Copyright © 1996-2023 Elated Communications. All rights reserved.
Affiliate Disclaimer | Privacy Policy | Terms of Use | Service T&C | Credits