Array functions in PHP - the way we do it - part 1

Hi,
  Back again! If you have read my previous posts then you will be sure this post is about PHP - the programming language that drives most major websites, at least more than 50% of them. Well we have already discussed how arrays are addressed in PHP. Now let's see how to do things with arrays without any panic and fear in our mind. Let me tell you PHP has a good amount of functions to manipulate arrays in all sorts of ways. This post will be as long as the great wall if I keep them all here. So, as they say, Break-it-down, I will break this post in several parts. First lets have a look at the functions available in PHP that can be used with arrays.

I found this list on php.net
  1. array_change_key_case — Changes all keys in an array
  2. array_chunk — Split an array into chunks
  3. array_combine — Creates an array by using one array for keys and another for its values
  4. array_count_values — Counts all the values of an array
  5. array_diff_assoc — Computes the difference of arrays with additional index check
  6. array_diff_key — Computes the difference of arrays using keys for comparison
  7. array_diff_uassoc — Computes the difference of arrays with additional index check which is performed by a user supplied callback function
  8. array_diff_ukey — Computes the difference of arrays using a callback function on the keys for comparison
  9. array_diff — Computes the difference of arrays
  10. array_fill_keys — Fill an array with values, specifying keys
  11. array_fill — Fill an array with values
  12. array_filter — Filters elements of an array using a callback function
  13. array_flip — Exchanges all keys with their associated values in an array
  14. array_intersect_assoc — Computes the intersection of arrays with additional index check
  15. array_intersect_key — Computes the intersection of arrays using keys for comparison
  16. array_intersect_uassoc — Computes the intersection of arrays with additional index check, compares indexes by a callback function
  17. array_intersect_ukey — Computes the intersection of arrays using a callback function on the keys for comparison
  18. array_intersect — Computes the intersection of arrays
  19. array_key_exists — Checks if the given key or index exists in the array
  20. array_keys — Return all the keys or a subset of the keys of an array
  21. array_map — Applies the callback to the elements of the given arrays
  22. array_merge_recursive — Merge two or more arrays recursively
  23. array_merge — Merge one or more arrays
  24. array_multisort — Sort multiple or multi-dimensional arrays
  25. array_pad — Pad array to the specified length with a value
  26. array_pop — Pop the element off the end of array
  27. array_product — Calculate the product of values in an array
  28. array_push — Push one or more elements onto the end of array
  29. array_rand — Pick one or more random entries out of an array
  30. array_reduce — Iteratively reduce the array to a single value using a callback function
  31. array_replace_recursive — Replaces elements from passed arrays into the first array recursively
  32. array_replace — Replaces elements from passed arrays into the first array
  33. array_reverse — Return an array with elements in reverse order
  34. array_search — Searches the array for a given value and returns the corresponding key if successful
  35. array_shift — Shift an element off the beginning of array
  36. array_slice — Extract a slice of the array
  37. array_splice — Remove a portion of the array and replace it with something else
  38. array_sum — Calculate the sum of values in an array
  39. array_udiff_assoc — Computes the difference of arrays with additional index check, compares data by a callback function
  40. array_udiff_uassoc — Computes the difference of arrays with additional index check, compares data and indexes by a callback function
  41. array_udiff — Computes the difference of arrays by using a callback function for data comparison
  42. array_uintersect_assoc — Computes the intersection of arrays with additional index check, compares data by a callback function
  43. array_uintersect_uassoc — Computes the intersection of arrays with additional index check, compares data and indexes by a callback functions
  44. array_uintersect — Computes the intersection of arrays, compares data by a callback function
  45. array_unique — Removes duplicate values from an array
  46. array_unshift — Prepend one or more elements to the beginning of an array
  47. array_values — Return all the values of an array
  48. array_walk_recursive — Apply a user function recursively to every member of an array
  49. array_walk — Apply a user function to every member of an array
  50. array — Create an array
  51. arsort — Sort an array in reverse order and maintain index association
  52. asort — Sort an array and maintain index association
  53. compact — Create array containing variables and their values
  54. count — Count all elements in an array, or something in an object
  55. current — Return the current element in an array
  56. each — Return the current key and value pair from an array and advance the array cursor
  57. end — Set the internal pointer of an array to its last element
  58. extract — Import variables into the current symbol table from an array
  59. in_array — Checks if a value exists in an array
  60. key — Fetch a key from an array
  61. krsort — Sort an array by key in reverse order
  62. ksort — Sort an array by key
  63. list — Assign variables as if they were an array
  64. natcasesort — Sort an array using a case insensitive "natural order" algorithm
  65. natsort — Sort an array using a "natural order" algorithm
  66. next — Advance the internal array pointer of an array
  67. pos — Alias of current
  68. prev — Rewind the internal array pointer
  69. range — Create an array containing a range of elements
  70. reset — Set the internal pointer of an array to its first element
  71. rsort — Sort an array in reverse order
  72. shuffle — Shuffle an array
  73. sizeof — Alias of count
  74. sort — Sort an array
  75. uasort — Sort an array with a user-defined comparison function and maintain index association
  76. uksort — Sort an array by keys using a user-defined comparison function
  77. usort — Sort an array by values using a user-defined comparison function
  Hmm! that's a long list. I promise all those are for manipulating or reading arrays.Yes there are 77 of them. Apart from these there are functions that return arrays of convert them to strings, like explode(), implode(), respectively. I will cover most of them but I will club the linked functions together. If you want a specific function to be explained in detail you can always leave a request in comments.
  OK, so let's see at the functions individually:
1) array_change_key_case - this function changes the character case of keys in a associative array. Means if you call it on a certain associative array, it will return the same array but with all keys changed to lower/upper case. If the keys have mixed lower and upper case characters then this function returns ...

--
Amit Kriplani
PHP Web/Application Developer
Blog:http://blog.amitkriplani.com
Mobile: +91-9913932644
MSN: amitk87@hotmail.com
Gmail: amitkriplani5@gmail.com
Yahoo: amitkriplani@ymail.com
Skype: amitkriplani
Twitter: @amitk87