What is array in PHP | PHP Tutorial for Beginners to Advance Full Course | part 14

What is Array :

        array is a data structure that stores one or more similar type of values in a single value.

 

Example

       if you want to store 50 numbers then instead of defining 50 variables its easy to define an array of 50 length

 

$a = [1,2,3,4,5,6,7,8,..........50]

 

Types Of Array in PHP

  1. Numeric array

  2. Associative array

  3. Multidimensional array

 

1.Numeric array

   Syntex :

   $variable_name = array(value1,value2,value3.......,value n);

 

Example 1 :

   $a = array(1,2,3,4,5,6,7,8);

 

Example 2 :

    $b = array(a,b,c,d,e,f,g,h);

 

 

2.Associative array

  Syntex :

   $variable_name = array('key'=>'value','key'=>'value');

 

  Example :

  $user_info = array(

      'name'=>'your_name',

      'email'=>'your_email',

      'age'=>'your_age',

 );

 

3. Multidimensional array

  Syntex :

   $variable_name = array(

        'key'=>array('key'=>'value','key'=>'value'),

        'key'=>array('key'=>'value','key'=>'value'),

   );

 

  Example :

  $marks = array(

           'a' =>array('hindi'=>'60','english'=>'40'),

           'b' =>array('hindi'=>'60','english'=>'40'), 

  );

 

 

Tutorial Topics