The most viewed posts

Registry Reviver

Web Development Services

How to clean up Windows Computer

About Desktop Icons in Windows Computer

Contact Me

Driver Booster

How to make a computer secure and run faster

Myanmar font and keyboard for Windows

CCleaner

Advanced System Care

The most viewed items

Dell Inspiron 5559

Desktop Hard Disk

Laptop RAM

HP ProBook 430

SONY Playstation Portable

External Hard Disk

Laptop

ZilaStar ICT Jun 12 2019, 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.

    To Contact
    Available Services
    Terms and Conditions