Sign in Registration

Basic functions for working with arrays in PHP, the array prefix


You have to work with arrays in any programming language; PHP has a number of special functions for conveniently working with arrays. Arrays allow you to store a large amount of information; they are complex structures that can contain various data.

There are several kinds of arrays in PHP. Arrays can be simple, they can be associative , in which there are key-value matches. Arrays can also be nested , one can easily nest another.

Most array functions begin with array_ to quickly apply the desired function. For example, the IDE or some editor may support auto-completion, in which case the developer just needs to write array_ and then all functions for working with arrays will be offered. But there are also functions whose names you need to remember or look at the reference book. Such functions begin without the array_ prefix .

Let's see what are the main functions in PHP for working with arrays :

  • array_flip - swaps keys with their values ​​in an array
  • array_intersect - calculates the convergence of arrays,
  • array_keys - returns all or some subset of array keys,
  • array_merge - merge one or more arrays,
  • array_pop - retrieves the last element of the array,
  • array_push - adds one or more elements to the end of the array,
  • array_rand - selects one or more random keys from an array,
  • array_reverse - returns an array with elements in reverse order,
  • array_search - searches for the given value in the array and returns the key of the first found element if successful,
  • array_shift - extracts the first element of the array,
  • array_slice - selects an array slice,
  • array - creates an array,
  • asort - sorts the array, keeping the keys,
  • count - counts the number of elements in an array or something in an object,
  • current - returns the current element of the array,
  • end - sets the internal array pointer to its last element,
  • in_array - checks if a value is present in the array
  • key - selects a key from an array
  • reset - sets the internal array pointer to its first element.

Thus, working with arrays in PHP is quite simple, just memorize a few simple functions and apply them to achieve the desired result.

Comments (0)
For commenting sign in or register.

Latest articles

Popular sections

Eqsash (Tools)

Android app - VK LAST USER ID, отучитель от зависимости и т.д.:
Available on Google Play

Amessage (Communication)

Login to the web version
Android app:
Available on Google Play

Share this

Subscribe to



IT notes - In simple language about the most necessary things (HTML, CSS, JavaScript, PHP, databases, Drupal, Bitrix, SEO, domains, security and more), PDF, 500 p.