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
    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>';
        }
    }

  2. #2
    Join Date
    Jan 2008
    Location
    india,kerala-god's own country
    Posts
    14,007

    Default

    http://php.flashwebhost.com/ramesh/day-6/day-6_2.php

    PHP Code:
    <?php

    $teams 
    = array();

    $team_KingsXIPunjab = array();

    $team_KingsXIPunjab['team'] = 'KingsXIPunjab';
    $team_KingsXIPunjab['player_name'] = 'Sewang';
    $team_KingsXIPunjab['price'] =  3000000;
    $team_KingsXIPunjab['batsman'] = 'yes';
    $team_KingsXIPunjab['spin bowler'] = 'yes';
    $team_KingsXIPunjab['wicket keepper'] = 'no';

    $team_DelhiDaredevils = array();

    $team_DelhiDaredevils['team'] = 'Delhi Daredevils';
    $team_DelhiDaredevils['player_name'] = 'Kevin Peterson';
    $team_DelhiDaredevils['price'] =  9000000;
    $team_DelhiDaredevils['batsman'] = 'yes';
    $team_DelhiDaredevils['spin bowler'] = 'no';
    $team_DelhiDaredevils['wicket keepper'] = 'yes';

    $team_ChennaiSuperKings = array();

    $team_ChennaiSuperKings['team'] = 'Chennai Super Kings';
    $team_ChennaiSuperKings['player_name'] = 'Dhoni';
    $team_ChennaiSuperKings['price'] =  1000000;
    $team_ChennaiSuperKings['batsman'] = 'yes';
    $team_ChennaiSuperKings['spin bowler'] = 'no';
    $team_ChennaiSuperKings['wicket keepper'] = 'yes';


    $teams[] = $team_KingsXIPunjab;
    $teams[] = $team_DelhiDaredevils;
    $teams[] = $team_ChennaiSuperKings;

    echo 
    '<h1>I P L TEAMS</h1>';

    foreach (
    $teams as $team) {
        echo 
    '<hr>';
        echo 
    '<b>Team:</b> '  $team['team']  . '<br>';
        echo 
    '<b>Name:</b> '  $team['player_name']  . '<br>';
        echo 
    '<b>Price:</b> Rs: '  $team['price']  . '/-<br>';
        echo 
    '<b>batsman:</b> '  $team['batsman']  . '<br>';
        echo 
    '<b>spin bowler:</b> '  $team['spin bowler']  . '<br>';
        echo 
    '<b>wicket keepper:</b> '  $team['wicket keepper']  . '<br>';

        if (
    $team['spin bowler'] == 'yes') {
            echo 
    '';
        }
    }

    echo 
    '<hr>';

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
  •