The most viewed posts

Registry Reviver

How to clean up Windows Computer

About Desktop Icons in Windows Computer

Driver Booster

CCleaner

How to make a computer secure and run faster

Myanmar font and keyboard for Windows

Advanced System Care

some (JavaScript Array Method)

Web Development Services

The most viewed items

Desktop Hard Disk

Dell Inspiron 5559

HP ProBook 430

SONY Playstation Portable

Laptop RAM

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