Page 1 of 2 12 LastLast
Results 1 to 10 of 27

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

Hybrid View

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

    Default

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

    Code:
      <?php
    
    $mobile = array();
    
    $mobile['Name'] = 'Reliance Mobile Phone';
    $mobile['Price'] = 5000;
    $mobile['Color'] = 'yellow';
    $mobile ['Sim'] = 'duel';
    $mobile ['Camera'] = '8mp';
    
    
    echo '<pre>';
    print_r($mobile);
    echo '</pre>';
    
    
    echo '<h1>Product Details</h1>';
    echo ' <b>Name:</b> ' . $mobile['Name'] . '<br>';
    echo ' <b>Price:</b>Rs: ' . $mobile['Price'] . '/-<br>';
    echo ' <b>Color:</b> ' . $mobile['Color'] . '<br>';
    echo ' <b>Sim:</b> ' . $mobile ['Sim'] . '<br>';
    echo ' <b>Camera:</b> ' . $mobile ['Camera'] . '<br>';
    Last edited by minisoji; 05-15-2014 at 09:26 AM.

  2. #2
    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.

  3. #3
    Join Date
    Nov 2009
    Posts
    76,596

    Default

    http://php.flashwebhost.com/sherly/hosting.php

    Code:
    <?php
    
    $company = array();
    
    $company['hosting'] ='Linux';
    
    $company['plan'] ='starter plan';
    
    $company['name'] ='FlashWebHost.com';
    
    $company['price'] =399;
    
    echo '<pre>';
    
    print_r ($company);
    
    echo '<pre>';
    
    echo $company['hosting'] . ' provide ' . strtoupper($company['name'])  . ' plan for $ ' . $company['price'];

  4. #4
    Join Date
    Feb 2005
    Location
    India
    Posts
    11,004

    Default


    http://php.flashwebhost.com/melbin/array_cars.php


    PHP Code:
     <?php

    $cars 
    = array();

    $car1 = array();

    $car1['brand'] = 'BMW X6';
    $car1['price'] =  13850000;
    $car1['available'] = 'yes';
    $car1['company'] = 'BMW';
    $car1['comments'] = '';

    $car2 = array();

    $car2['brand'] = 'Bugatti Veyron';
    $car2['price'] =  120000000;
    $car2['available'] = 'yes';
    $car2['company'] = 'Bugatti';
    $car2['comments'] = 'Bugatti Veyron is the verified fastest car in the world';

    $car3 = array();

    $car3['brand'] = 'Ferrari FF';
    $car3['price'] =  34000000;
    $car3['available'] = 'yes';
    $car3['company'] = 'Ferrari';
    $car3['comments'] = '';

    $cars[] = $car1;
    $cars[] = $car2;
    $cars[] = $car3;

    echo 
    '<h1>Available Car Models</h1>';

    foreach (
    $cars as $car) {
        echo 
    '<hr>';
        echo 
    '<b>Brand : </b> '  strtoupper($car['brand'])  . '<br>';
        echo 
    '<b>Price : </b> Rs: '  $car['price'] . '/-<br>';
        echo 
    '<b>Company : </b> '  strtoupper($car['company']) . '<br>';
        echo 
    '<b>In Stock : </b> '  $car['available'] . '<br>';
        echo 
    '<b>Comments : </b> '  '<b>' $car['comments'] . '<b><br>';
    }

    echo 
    '<hr>';
    VIDEO WORLD : LATEST HOLLYWOOD || BOLLYWOOD || SOUTH INDIAN VIDEOS || TRAILERS

  5. #5
    Join Date
    Nov 2009
    Posts
    76,596

    Default

    http://php.flashwebhost.com/sherly/tyres.php

    Code:
    <?php
    
    $tyres = array();
    
    $tyres1 = array();
    
    $tyres1 ['brand'] = 'Apollo Tyres';
    
    $tyres1 ['size'] = 'P 155/70R 13 75H';
    
    $tyres1  ['Price'] = '3028';
    
    $tyres1  ['available'] = 'yes';
    
    $tyres2 = array();
    
    $tyres2 ['brand'] = 'MRF';
    
    $tyres2 ['size'] = 'P 145/80R 12 74T';
    
    $tyres2 ['Price'] = '2721';
    
    $tyres2 ['available'] = 'Yes';
    
    $tyres3 =array ();
    
    $tyres3 ['brand'] = 'JK Tyre & Indust';
    
    $tyres3 ['size'] = 'P 132/70R 13 75H';
    
    $tyres3 ['Price'] = '4991';
    
    $tyres3 ['available'] = 'Yes';
    
    $tyres4 = array();
    
    $tyres4 ['brand'] = 'CEAT';
    
    $tyres4 ['size'] = 'P 132/23O 13 75H';
    
    $tyres4 ['Price'] = '4211';
    
    $tyres4 ['available'] = 'Yes';
    
    $tyres[] = $tyres1;
    
    $tyres[] = $tyres2;
    
    $tyres[] = $tyres3;
    
    $tyres[] = $tyres4;
    
    foreach ($tyres as $tyre)    {
    echo ' Brand : ' . $tyre['brand'] . '<br>';
    
    echo ' Size : ' . $tyre['size'] . '<br>';
    
    echo ' price : ' . $tyre['color'] . '<br>';
    
    echo ' Available : ' . $tyre['available'] . '<br>';
    
    if ($tyre ['available'] == 'Yes'){
    
    echo '<a href="">Click here</a>  to order your ' . $tyre['brand'] . ' tyre ' ;
    
    }
    
    if ($tyre ['price'] == '') { 
    
    echo '<font size="" size="#ff0000"> ' .  $tyre['size'] .'</font>' . ' CEAT - out of stock'; 
    
    }
    
    echo '<hr>';
    
    }

  6. #6
    Join Date
    Feb 2007
    Posts
    26,214

    Default

    DAY 6 PHP PROGRAMMING

    http://php.flashwebhost.com/tom/day_6_array_1.php

    Code:
    <?php
    
    
    $movie = array() ;
    
    
    $movie['name'] = 'Mr. Fraud';
    $movie['starring'] = 'Mohanlal, Manjari Fadnis';
    $movie['director'] = 'B Unnikrishnan';
    $movie['rate'] = '90';
    $movie['theatre'] = 'EVM Kavitha - Ernakulam';
    
    
    echo '<pre>';
    print_r($movie);
    echo '</pre>';
    
    
    echo '<h1>Movie Details</h1>';
    
    
    echo '<b>Movie Name</b>: ' . $movie['name'] . '<br>';
    echo '<b>Star Name</b>: ' . $movie['star'] . '<br>';
    echo '<b>Director Name</b>: ' . $movie['director'] . '<br>';
    echo '<b>Ticket Rate</b>: ' . $movie['rate'] . '<br>';
    echo '<b>Theatre Name</b>: ' . $movie['theatre'] ;

  7. #7
    Join Date
    Nov 2009
    Location
    kerala
    Posts
    19,076

    Default

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

    PHP Code:

    <?php


    $monitor 
    = array();

    $monitor1 ['brand'] = 'Dell';

    $monitor1 ['size'] = 27;

    $monitor1 ['price'] = 6000;

    $monitor2 = array();

    $monitor2 ['brand'] = 'Viewsonic';

    $monitor2 ['size'] = 23;

    $monitor2 ['price'] = 2000;

    $monitor3 =array ();

    $monitor3 ['brand'] = 'Samsung';

    $monitor3 ['size'] = 24;

    $monitor3 ['price'] = 4000;

    $monitor4 = array();

    $monitor4 ['brand'] = 'LG';

    $monitor4 ['size'] = 19;

    $monitor4 ['price'] = 1500;

    $monitor[] = $monitor1;

    $monitor[] = $monitor2;

    $monitor[] = $monitor3;

    $monitor[] = $monitor4;


    foreach (
    $monitor as $ledMonitor)  

      {

    echo 
    ' Brand : ' $ledMonitor['brand'] . '<br>';

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

    echo 
    ' Price : ' $ledMonitor['price'] . '<br>';

    if (
    $ledMonitor['price'] <=2000 ) {

    echo 
    '<div style=color:red;font-weight:bold>Exclusive offer !</div>';}

    elseif (
    $ledMonitor['price'] <=4000 ){

    echo 
    '<div style=color:#0033ff;font-weight:bold>HURRY ! . Limitted-time offer !</div>';

    }

    else {   

     echo 
    '<div style=color:#009900;font-weight:bold>Premium offer. FREE multimedia speakers. Before.<span style=text-decoration:line-through>Rs. 7,699</span></div>';

    }

    echo 
    '<hr>';

    }
    Last edited by Vahaa11; 05-15-2014 at 11:13 AM.

  8. #8
    Join Date
    Nov 2004
    Location
    India
    Posts
    65

    Default

    http://php.flashwebhost.com/stefin/games.php

    Code:
    <?php
    
    
    $games = array();
    
    
    $game1 = array();
    
    
    $game1['name'] = 'G.T.A Vice city';
    $game1['price'] =  255;
    $game1['available'] = 'yes';
    $game1['supplier'] = 'RockStar Games';
    
    
    $game2 = array();
    
    
    $game2['name'] = 'G.T.A San Andreas';
    $game2['price'] =  215;
    $game2['available'] = 'yes';
    $game2['supplier'] = 'RockStar Games';
    
    
    $game3 = array();
    
    
    $game3['name'] = 'Mine craft';
    $game3['price'] =  317.20;
    $game3['available'] = 'yes';
    $game3['supplier'] = 'Mojang';
    
    
    $game4 = array();
    
    
    $game4['name'] = 'Assasins creed';
    $game4['price'] =  412;
    $game4['available'] = 'yes';
    $game4['supplier'] = 'Ubsoft';
    
    
    $games[] = $game1;
    $games[] = $game2;
    $games[] = $game3;
    $games[] = $game4;
    
    
    echo '<h1>Games</h1>';
    foreach ($games as $game) {
    echo '<hr>';
      echo '<hr>';
      echo '<b>name:</b> ' . $game['name']  . '<br>';
      echo '<b>price:</b> RS: ' . $game['price']  . '/-<br>';
      echo '<b>supplier:</b> ' . $game['supplier']  . '<br>';
      echo '<b>available:</b> ' . $game['available']  . '<br>';
     
    if ($game['available'] == 'yes') {
            echo '<p>Game in stock, buy it before your friends do </p>';
    }
    }
    echo '<hr>';

  9. #9
    Join Date
    Sep 2003
    Posts
    3,040

    Default

    Quote Originally Posted by stefin View Post
    http://php.flashwebhost.com/stefin/games.php

    Code:
    <?php
    $games = array();
    
    
    $game1 = array();
    
    
    $game1['name'] = 'G.T.A Vice city';
    $game1['price'] =  255;
    $game1['available'] = 'yes';
    $game1['supplier'] = 'RockStar Games';
    
    
    $game2 = array();
    
    
    $game2['name'] = 'G.T.A San Andreas';
    $game2['price'] =  215;
    $game2['available'] = 'yes';
    $game2['supplier'] = 'RockStar Games';
    
    
    $game3 = array();
    
    
    $game3['name'] = 'Mine craft';
    $game3['price'] =  317.20;
    $game3['available'] = 'yes';
    $game3['supplier'] = 'Mojang';
    
    
    $game4 = array();
    
    
    $game4['name'] = 'Assasins creed';
    $game4['price'] =  412;
    $game4['available'] = 'yes';
    $game4['supplier'] = 'Ubsoft';
    
    
    $games[] = $game1;
    $games[] = $game2;
    $games[] = $game3;
    $games[] = $game4;
    
    
    echo '<h1>Games</h1>';
    foreach ($games as $game) {
    echo '<hr>';
      echo '<hr>';
      echo '<b>name:</b> ' . $game['name']  . '<br>';
      echo '<b>price:</b> RS: ' . $game['price']  . '/-<br>';
      echo '<b>supplier:</b> ' . $game['supplier']  . '<br>';
      echo '<b>available:</b> ' . $game['available']  . '<br>';
     
    if ($game['available'] == 'yes') {
            echo '<p>Game in stock, buy it before your friends do </p>';
    }
    }
    echo '<hr>';
    Good program, TF2 missing ?
    Become PHP Expert in 30 days
    FreeMarriage.com - Free Online Matrimonial
    FlashWebHost.com - Professional Web Hosting, Designing.

  10. #10
    Join Date
    Oct 2003
    Location
    Kochi, Kerala, India
    Posts
    21,389

    Default

    http://php.flashwebhost.com/vineesh/..._6_array_2.php

    PHP Code:
    <?php

    $timeTables 
    = array();

    $timeTable1 = array();

    $timeTable1[day] = 'monday';
    $timeTable1[teacher] = 'murali';
    $timeTable1[subject] = 'english';
    $timeTable1[period] = 'first period';
    $timeTable1[availability] = 'present';


    $timeTable2 = array();

    $timeTable2[day] = 'tuesday';
    $timeTable2[teacher] = 'chandrika';
    $timeTable2[subject] = 'chemistry';
    $timeTable2[period] = 'second period';
    $timeTable2[availability] = 'present';


    $timeTable3 = array();

    $timeTable3[day] = 'wednesday';
    $timeTable3[teacher] = 'alice';
    $timeTable3[subject] = 'biology';
    $timeTable3[period] = 'third period';
    $timeTable3[availability] = 'absent';

    $timeTables[] = $timeTable1;
    $timeTables[] = $timeTable2;
    $timeTables[] = $timeTable3;


    echo 
    '<h2><font=color:red;>Class info: </font> </h2>';

    foreach (
    $timeTables as $timeTable) {
        echo 
    '<b> <font color=blue>Day: </font></b>' ucwords($timeTable[day]) . '<br>';
        echo 
    '<b> <font color=blue>Name of the Teacher: </font></b>' ucwords($timeTable[teacher]) . '<br>';
        echo 
    '<b> <font color=blue>Subject:</font></b> ' ucwords($timeTable[subject]) . '<br>';
        echo 
    '<b> <font color=blue>Period: </font></b> ' ucwords($timeTable[period]) . '<br>';

        if (
    $timeTable[availability] == 'present') {
            echo 
    '<p>Students, teacher is on the way, you may go to your classes.</p>';

        } if (
    $timeTable[availability] == 'absent') {
            echo 
    '<p>Heyy.. teacher is absent today, you may go home :) </p>';
        }
    }

Page 1 of 2 12 LastLast

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
  •