Results 1 to 10 of 27

Thread: Day 6 - Associative Array - Become PHP Expert in 30 days

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #21
    Join Date
    Apr 2005
    Posts
    46,704

    Default

    http://php.flashwebhost.com/mini/array_2.php


    Code:
    <?php
    
    $mobiles = array();
    
    
    $mobile1 = array();
    
    $mobile1 ['name'] = 'Samsung';
    $mobile1 ['price'] = 4000;
    $mobile1 ['color'] = 'white';
    $mobile1 ['available'] = 'yes';
    
    
    $mobile2 = array();
    $mobile2 ['name'] = 'Reliance';
    $mobile2 ['price'] = 5000;
    $mobile2 ['color'] = 'yellow';
    $mobile2 ['available'] = 'yes';
    
    $mobile3 = array();
    
    $mobile3 ['name'] = 'nokia';
    $mobile3['price'] = 6000;
    $mobile3 ['color'] = 'red';
    $mobile3 ['available'] ='no';
    
    $mobiles[] = $mobile1;
    $mobiles[] = $mobile2;
    $mobiles[] = $mobile3;
    /*
    echo '<pre>';
    print_r($mobiles);
    echo'</pre>';*/
    
    
    echo '<h1>Menu</h1>';
    
    foreach ($mobiles as $mobile) {
        echo '<hr>';
        echo '<b>Name:</b> '  . $mobile['name']  . '<br>';
        echo '<b>Price:</b> Rs: '  . $mobile['price']  . '/-<br>';
        echo '<b>Color:</b> '  . $mobile['color']  . '<br>';
        echo '<b>Available:</b> '  . $mobile['available']  . '<br>';
    
        if ($mobile ['available'] == 'yes') {
            echo '<p>Product in stock, buy before it becomes out of stock.</p>';
        }
    
    if ($mobile ['available'] == 'no'){echo '<p>Out of Stock.</P>';}
    
    }
    
    echo'<hr>';
    Last edited by minisoji; 05-17-2014 at 07:02 AM.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •