Cheat Sheets & Quick References

PHP Array Functions Quick Reference

A practical overview of common PHP array functions for searching, transforming, filtering and combining arrays.

Overview

PHP arrays are ordered maps used for lists, dictionaries and mixed collections. The standard library includes functions for common array operations.

Frequently used functions

  • count() returns the number of elements.
  • array_map() applies a callback to array elements.
  • array_filter() keeps elements that pass a callback.
  • array_values() returns numerically indexed values.
  • array_keys() returns the keys.
  • in_array() checks whether a value exists.
  • array_key_exists() checks whether a key exists.
  • array_merge() combines arrays.
  • array_unique() removes duplicate values.
  • array_column() extracts values from a column in a multidimensional array.

Practical notes

Use strict comparison where appropriate, especially with in_array(). Remember that array_filter() preserves keys; call array_values() if a zero-based list is required. Read each function's behavior for empty values and key collisions.

Official resource

PHP array functions: https://www.php.net/manual/en/ref.array.php