PHP Arrays: Initialization with Set of Elements

It is possible to insert elements into the array one by one. But in some cases, we know the elements of an array before hand. In such cases, we can make use of the function array(). The elements to be inserted can be specified as parameters to the array.

$days = array("Sunday", "Monday", "Tuesday", "Wednesday",
    "Thursday", "Friday", "Saturday");

You will notice that the elements are inserted starting from the index 0

array(7) {
  string(6) "Sunday"
  string(6) "Monday"
  string(7) "Tuesday"
  string(9) "Wednesday"
  string(8) "Thursday"
  string(6) "Friday"
  string(8) "Saturday"

Leave a Reply

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

You are commenting using your 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