What is an Array in PHP ?
Array in PHP is a data structure that stores one or more similar type of values in a single unit.The array functions are allows you to access and manipulate the arrays. It’s a dynamic data structure, so it can grow and shrink at runtime. There is no memory wastage because size of linked list can increase or decrease at run time.
An array in PHP, there are three types of arrays:
1. Indexed arrays – Arrays with a numeric index. These types of arrays can be used to store any type of elements, but an index is always a number.
2. Associative arrays – Arrays with named keys. These types of arrays are similar to the indexed arrays.
3. Multidimensional arrays – Array contains one or more arrays.
Advantages of array in PHP:
1. Supports: One-dimensional arrays.
2. Supports: multi-dimensional arrays.
3. Less Code: You don’t need to define multiple variables.
4. Easy to traverse: You can traverse all the elements of an array with help of single loop.
5. Sorting: You can sort the elements of array.
Some PHP Functions:
array() Creates an array.
array_fill() Fills an array with values.
array_fill_keys() Fills an array with values, specifying keys.
array_keys() Returns all the keys of an array.
array_merge() Merges one or more arrays into one array.
array_pop() Deletes the last element of an array.
array_push() Inserts one or more elements to the end of an array.
array_reverse() Returns an array in the reverse order.
array_sum() Returns the sum of the values in an array.
array_unique() Removes duplicate values from an array.
array_unshift() Adds one or more elements to the beginning of an array.
array_values() Returns all the values of an array.
rsort() Sorts an indexed array in descending order.
sort() Sorts an indexed array in ascending order.
Tags : | PHP Questions | PHP interview questions | PHP FAQs | PHP | Array in PHP |
*Disclaimer: We have published the above images and information for reference purpose only, for any changes on the content we refer to visit the Official Website to get the latest info.
NOTE: Walkinsbook.Com Employees will not call any candidates towards Job Offer or Job assistance. We never charge any candidates for Jobs. Please be aware of fraudulent Calls or Emails.
Array in