Join TalkersCode Now !

Get Latest Tutorials And Links On Web Development
And Get Existing Offers Via Email

PHP Arrays

PHP Arrays

PHP Array is used to store similar multiple type of values in a single variable.PHP has three different type of arrays Numeric Array, Associative Array, Multidimensional Array.

Creating An Array

You can create array by using array() function or long method


/*Long Method*/

Numeric Array

Numeric Array are those array which are used to store any kind of value like number, string etc. By default array index starts from zero.

$val=array(2324, 434, 45, 4849);

foreach($val as $array)
  echo $array;

Associative Array

Associative array will have their index as string so that you can establish a strong association between key and values.

$rollno = array("Aman"=>"1", "Rahul"=>"21", "Karan"=>"16");

foreach($rollno as $array)
  echo $array;

/*Or you can use long method*/
echo $rollno['Aman'];
echo $rollno['Rahul'];
echo $rollno['Karan'];

Multidimensional Array

Multidimensional array are used to make array in array like each element in the main array can also be an array. And each element in the sub-array can be an array, and so on. Values in the multi-dimensional array are accessed using multiple index.

$student_info = array( 
	"aman" => array
	 "rollno" => 2,	    
	 "course" =>"B-Tech",	    
	"rahul" => array
	 "rollno" => 21,	    
	 "course" => "BCA",	    
	"karan" => array
	 "rollno" => 16,	    
	 "course" =>"MCA",	    

echo $rollno['aman'][course];
echo $rollno['rahul'][course];
echo $rollno['karan'][course];

Join Us With Our 21000+ Subscribers And Get Our Latest Tutorials Update Via Email

Are You Starting A New Blog
Do You Want Best Web Hosting?

Try World's Best Web Hosting Provider BlueHost
At Just $3.95/mo

Hurry Up! Limited Time Offer

Yes, I Want To Check Out BlueHost

Check The World's Best SEO And All-In-One Marketing Toolkit
For Digital Marketing Professionals SEMRUSH