1 / 4
Computer Service
2 / 4
Networking Service
3 / 4
Web Development Service
4 / 4
Software Development Service
TNW - ICT Solutions
  • Home
  • Available Courses 
  • Available Services 
  • Website Samples 
  • Search Log In
  •  Normally There are three types of array: Indexed Array, Associative Array and Multi-Dimentional Array.

    1. Indexed Array (Works with number)
    
    <?php
    $snack = array('Banana', 'Ice-cream', 'Coconet', 'Mango', 'Orange');
    $snack[1]='Alcohol';
    echo $snack[1];
    //print_r($snack);
    ?>
     
    
     2. Associative Array (Works with name)
    
    <?php
    $snack = array('Banana' => 100, 'Apple' => 200, 'Cake' => 300);
    echo 'The cake is '.$snack['Cake']. ' Kyat.';
    ?>
    
    
    3. Multi-Dimentional Array
    
    <?php
    $food = array('Healthy'=>array('Salad'=>200, 'Milk'=>100, 'Coconet'=>200),
                  'Unhealthy'=>array('Alcohol'=>200, 'Beer'=>300));
    
    foreach($food as $element => $inner_array){
      echo '<br /><strong>'.$element.'</strong><br />';
      foreach($inner_array as $inner_element => $item){
        echo $inner_element.' = '.$item.'<br />';
      }
    }
    ?>