All about Array in PHP

1. Array creation

  • using array() built in function for creating array in php code.

$a = array (
‘l’ => 10,
‘11’ => “test”,
‘another element’
);
var_dump ($a);

Output:
array(3) {
[“l”]=>
int(10)
[11]=>
string(4) “test”
[12]=>
string(15) “another element”
}

2. Using the array operator

  • The array operator [ ] is used to address an element of a particular array. For example,

3. Counting the number of elements in an array
4. Assigning values to multiple variables from an array

  • using the list() function
  • advantages and disadvantages of list() function

5.   Multi dimensional array
6.   Navigation arrays

  • Using for loop by counting the numbers of elements in an array
  • using foreach iteration
  • Advantages and dis advantages
  • using the internal Pointer
  • using a callback function

7. Manipulating array keys

array_keys(),array_key_exists(),array_change_key_case(),ksort(),krsort()

  • checking if an element exists
  • changing the arrays of keys
  • sorting an array by its keys
  • sorting parameter for sorting functions

8. Manipulating arrays

asort(),arsort(),

9. Sorting multidimensional arrays

array_multisort()

10. Random and shuffle array

shuffle(), array_rand()

11. Merging arrays

array_merge(),array_merge_recursive()

12. Intersection and difference

array_intersect(),array_intersect_assoc(),array_diff(),array_diff_assoc()

13. Serializing arrays

serialize(),unserialize()

Advertisements

About Mazharul Anwar

A PHP and javascript nerd believe in web applications and open source goodness. Ex MS Windows user converted to linux fanboy and love gadgets. Coding in python and maintaining servers become my passion. Website performance and optimization geek.
This entry was posted in Programming and tagged , , . Bookmark the permalink.

One Response to All about Array in PHP

  1. what a great site and informative posts, I will add a backlink and bookmark your site. Keep up the good work!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s