Please login to start chat

ICT Solutions 2019-01-28 12:15:54
Category : php tutorials

Array in php

 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 />';
  }
}
?>

 

Comments:

No comment to show.

Available Services
Download Android Application