PHP array() Function
In this article, you will explore the capabilities of the Func Array / array() function in PHP. You will start with a brief introduction to the concept of arrays, including how they are created and populated.
From there, you will delve into more advanced topics. By the end of this article, you will have a clear understanding of how arrays work in PHP, allowing you to apply these skills to a variety of technical programming tasks that you may encounter in the future. With the Func Array / array() function, you have the power to store and manipulate data in an array.
What is array() function in PHP?
The array()
function in PHP is a built-in function that is used to create arrays. It is a versatile function that allows you to create both indexed arrays (arrays with numeric keys) and associative arrays (arrays with string keys).
There are three types of array in PHP:
- Indexed arrays – With numerical indices.
- Associative arrays – Key-value arrays.
- Multidimensional arrays – arrays containing multiple arrays.
Syntax
array(value1, value2, value3, etc.)
Syntax for associative arrays
array(key=>value,key=>value,key=>value,etc.)
You can create arrays of any size, with any type of data, and store information within them. Whether you need to store a collection of strings, an array of integers, or a combination of both, this function has you covered.
Example: 
When we talk about Func Array then, Associative array named $user_info should be created as follows:
Example: 
Following is an example of looping through each element of an associative array:
Example: 
Example: 
Conclusion
The array() function in PHP OR Func Array is a powerful tool that allows you to store and manipulate data in an array. Whether you need to create an array, access its elements, loop through its elements, add elements to it, or sort its elements, the array() function has you covered. By mastering the array() function, you will be able to perform a wide range of tasks in PHP with ease.