PHP

Array Examples in PHP

The following list provides a few Array Examples in PHP.

  1. Create an Indexed array and display its elements using both for loop as well as foreach loop.
  2. When do we use associative array rather than an indexed array? Create a program to demonstrate how to create an associative array.
  3. Find the sum of elements of a one-dimensional array.
  4. Linear Search and Binary search in PHP.
  5. Sort the elements of an array in PHP.
  6. Demonstrate a two-dimensional associative array.
  7. Create a menu-driven program to perform the following operations: (i) Matrix Addition (ii) Matrix Subtraction (iii) Matrix Multiplication (iv) Matrix Transpose
  8. The following information should be displayed about an array: (i) Total number of values (ii) All the keys of the array (iii) All the values
  9. Sort the array in ascending as well descending order using array built-in function.
  10. Also, sort the array in ascending as well as descending order of keys.
  11. Perform the sorting on an array using (i) user-defined comparison function for values (ii) user-defined comparison function for keys.
  12. Write a program to perform following operations on an array using built-in functions on arrays: (i) Shuffle the array (ii) Find square root of every element of the array (iii) Eliminate duplicates from the array (iv) Find sum of all elements of the array (v) Reverse the array (vi) fills an array with specified values
  13. Perform following operations on arrays: (i) Find array difference (ii) array intersection.
  14. Create an associative array by combining the elements of one array as the keys and the elements of another array as values.
  15. Write a program to split an array.

Further Reading

Examples of Array Functions in PHP

Basic Programs in PHP

Registration Form Using PDO in PHP

You may also like...