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. #11
    Join Date
    Nov 2009
    Location
    kerala
    Posts
    19,076

    Default Associative Array example 2

    http://php.flashwebhost.com/sibichan...ray_2_eg_1.php

    PHP Code:

    <?php

    $shoes 
    = array();

    $shoes1 = array();

    $shoes1 ['brand'] = 'Puma';

    $shoes1 ['size'] = '7';

    $shoes1 ['color'] = 'Red';

    $shoes1 ['available'] = 'No';

    $shoes2 = array();

    $shoes2 ['brand'] = 'Nike';

    $shoes2 ['size'] = 'Puma';

    $shoes2 ['color'] = 'Blue';

    $shoes2 ['available'] = 'Yes';

    $shoes3 =array ();

    $shoes3 ['brand'] = 'Reebok';

    $shoes3 ['size'] = 'Puma';

    $shoes3 ['color'] = 'Black';

    $shoes3 ['available'] = 'Yes';

    $shoes4 = array();

    $shoes4 ['brand'] = 'Adidas';

    $shoes4 ['size'] = 'Puma';

    $shoes4 ['color'] = 'White';

    $shoes4 ['available'] = 'Yes';

    $shoes[] = $shoes1;

    $shoes[] = $shoes2;

    $shoes[] = $shoes3;

    $shoes[] = $shoes4;

    foreach (
    $shoes as $shoe)    {
    echo 
    ' Brand : ' $shoe['brand'] . '<br>';

    echo 
    ' Size : ' $shoe['size'] . '<br>';

    echo 
    ' Color : ' $shoe['color'] . '<br>';

    echo 
    ' Available : ' $shoe['available'] . '<br>';

    if (
    $shoe ['available'] == 'Yes'){

    echo 
    '<a href="">Click here</a>  to order your ' $shoe['brand'] . ' shoe ' ;

    }

    if (
    $shoe ['color'] == 'Red') { 

    echo 
    '<font size="" color="#ff0000"> ' .  $shoe['color'] .'</font>' ' color puma shoe - out of stock'

    }

    echo 
    '<hr>';

    }
    Last edited by Vahaa11; 05-15-2014 at 08:54 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
  •