ARRAY IN PHP<br />Department of CE/IT<br />
Array<br />An array stores multiple values in one single variable.<br />..contains value set<br />each element has a value...
Department of CE/IT<br />
What is an Array?<br />A variable is a storage area holding a number or text. The problem is, a variable will hold only on...
Types of Arrays<br />In PHP, there are three kind of arrays:<br />Numeric array - An array with a numeric index<br />Assoc...
Initializing Arrays<br />No of ways to initialize the array.<br />For e.g.<br />$ncststu[] = “Sri”;<br />	$ncststu[] = “Ra...
Creating an array<br />There are more ways to create an array in PHP. Maybe the most easiest way to create our color list ...
Display the array content<br />If you want only display one element of the array then you can just write the following cod...
Associative Arrays<br />An associative array, each ID key is associated with a value.<br />When storing data about specifi...
Example<br />In this example we use an array to assign ages to the different persons:<br />      $ages = array("Peter"=>32...
Finding the Size of an Array:<br />To find the size of an array, use the function count().count() takes one argument, whic...
The End.<br />Department of CE/IT<br />
Upcoming SlideShare
Loading in …5
×

Array in php

1,179 views
1,113 views

Published on

Published in: Education, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,179
On SlideShare
0
From Embeds
0
Number of Embeds
66
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Array in php

  1. 1. ARRAY IN PHP<br />Department of CE/IT<br />
  2. 2. Array<br />An array stores multiple values in one single variable.<br />..contains value set<br />each element has a value, data stored in the element.<br />And has a key by which the element can be referred to.<br />Department of CE/IT<br />
  3. 3. Department of CE/IT<br />
  4. 4. What is an Array?<br />A variable is a storage area holding a number or text. The problem is, a variable will hold only one value.<br />An array is a special variable, which can store multiple values in one single variable.<br />Department of CE/IT<br />
  5. 5. Types of Arrays<br />In PHP, there are three kind of arrays:<br />Numeric array - An array with a numeric index<br />Associative array - An array where each ID key is associated with a value<br />Multidimensional array - An array containing one or more arrays<br />Department of CE/IT<br />
  6. 6. Initializing Arrays<br />No of ways to initialize the array.<br />For e.g.<br />$ncststu[] = “Sri”;<br /> $ncststu[] = “Raja”;<br /> $ncststu[] = “Lakshmi”;<br />$ncststu[123] = “Sri”;<br /> $ncststu122] = “Raja”;<br /> $ncststu[121] = “Lakshmi”;<br />$ncststu = array (“Sri”, “Raja”, “Lakshmi”);<br />to change the indices of the array use => operator.<br />Department of CE/IT<br />
  7. 7. Creating an array<br />There are more ways to create an array in PHP. Maybe the most easiest way to create our color list array is the following:<br />other sollution is to initialise array elements one-by-one as follows:<br />Department of CE/IT<br />$colorList = array("red","green","blue","black","white");<br />$colorList[0] = "red";<br />$colorList[1] = "green";<br />$colorList[2] = "blue";<br />$colorList[3] = "black";<br />$colorList[4] = "white";<br />
  8. 8. Display the array content<br />If you want only display one element of the array then you can just write the following code:<br />This code will display the text "red". However you may want to display all elements in the array. You can write a loop and display them like this:<br />Department of CE/IT<br />echo $colorList[0];<br />for ($i=0;$i<=4;$i++){<br />echo $colorList[$i];<br />}<br />
  9. 9. Associative Arrays<br />An associative array, each ID key is associated with a value.<br />When storing data about specific named values, a numerical array is not always the best way to do it.<br />With associative arrays we can use the values as keys and assign values to them.<br />Department of CE/IT<br />
  10. 10. Example<br />In this example we use an array to assign ages to the different persons:<br /> $ages = array("Peter"=>32, "Quagmire"=>30, "Joe"=>34); <br />Department of CE/IT<br />
  11. 11. Finding the Size of an Array:<br />To find the size of an array, use the function count().count() takes one argument, which is the array, and returns an integer represents the number of the elements of this array.<br />Department of CE/IT<br />
  12. 12. The End.<br />Department of CE/IT<br />

×