Results 1 to 10 of 42

Thread: Day 5 - Array - Become PHP Expert in 30 days

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2004
    Location
    India
    Posts
    65

    Default

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

    Code:
    <?php
    $garden = array('mango tree', 'apple tree', 'cherry tree', 'Jackfruit tree', 'neem tree', 'mulberry tree', 'coconut tree');
    
    
    echo '<pre>';
    print_r($garden);
    echo '</pre>';
    echo '<p>The Gardener Is Going To Plant Four More Trees In His $garden array</p>';
    
    
    $garden[] = 'bamboo tree';
    $garden[] = 'rubber tree';
    $garden[] = 'teak tree';
    $garden[] = 'rose wood';
    
    
    echo '<pre>';
    print_r($garden);
    echo '</pre>';

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

    Default

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

    Code:
    <?php
    
    
    $animals = array('leapord', 'monkey', 'elephant', 'wolf', 'tiger', 'lion', 'giraffe');
    
    
    $numberOfAnimals = count($animals);
    
    
    echo '<p>We Have ' . $numberOfAnimals . ' Animals In Our Zoo.</p>';

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

    Default

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

    Code:
    <?php
    $garden = array('mango tree', 'apple tree', 'cherry tree', 'Jackfruit tree', 'neem tree', 'mulberry tree', 'coconut tree');
    
    
    echo '<pre>';
    print_r($garden);
    echo '</pre>';
    echo '<p>The Gardener Is Going To Plant Four More Trees In His $garden array</p>';
    
    
    $garden[] = 'bamboo tree';
    $garden[] = 'rubber tree';
    $garden[] = 'teak tree';
    $garden[] = 'rose wood';
    
    
    echo '<pre>';
    print_r($garden);
    echo '</pre>';

    Good code, $garden can be changed to $forest (or $trees), how can some one grow so much trees in a garden

    Try the code with foreach.

    Code:
    foreach ($garden as $plant) {
        echo $plant;
        echo '<br>';
    }
    Become PHP Expert in 30 days
    FreeMarriage.com - Free Online Matrimonial
    FlashWebHost.com - Professional Web Hosting, Designing.

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

    Default

    DAY 5 PHP PROGRAMMING

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

    Code:
    <?php
    
    
    $mohanlalMovies = array('Mr. Fraud', 'Drishyam', 'Geethanjali', 'Red Wine', 'Ladies and Gentleman', 'Lokpal', 'Karmayodha', 'Run Baby Run', 'Spirit', 'Grandmaster', 'Casanova');
    
    
    echo $mohanlalMovies [0];
    
    
    echo '<br>';
    
    
    echo $mohanlalMovies [1];
    
    
    echo '<br>';
    
    
    echo $mohanlalMovies [7];
    
    
    echo '<br>';
    
    
    echo $mohanlalMovies [8];
    
    
    echo '<br>';
    
    
    echo $mohanlalMovies [9];

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

    Default

    DAY 5 PHP PROGRAMMING

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

    Code:
    <?php
    
    
    $mohanlalMovies = array('Mr. Fraud', 'Drishyam', 'Geethanjali', 'Red Wine', 'Ladies and Gentleman', 'Lokpal', 'Karmayodha', 'Run Baby Run', 'Spirit', 'Grandmaster', 'Casanova');
    
    
    echo '<pre>';
    
    
    print_r($mohanlalMovies);
    
    
    echo '</pre>';
    
    
    $mohanlalHitMovies = array('Drishyam', 'Narasimham', 'Aaram Thampuran', 'Spadikam', 'Thenmavin Kombathu', 'Manichithrathazhu', 'Devasuram', 'Kilukkam', 'Chithram', 'Irupatham Noottandu');
    
    
    echo '<pre>';
    
    
    var_dump($mohanlalHitMovies);
    
    
    echo '</pre>';

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

    Default

    DAY 5 PHP PROGRAMMING

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

    Code:
    <?php
    
    
    $mohanlalMovies = array('Mr. Fraud', 'Drishyam', 'Geethanjali', 'Red Wine', 'Ladies and Gentleman', 'Lokpal', 'Karmayodha', 'Run Baby Run', 'Spirit', 'Grandmaster', 'Casanova');
    
    
    $numberOfMovies = count($mohanlalMovies);
    
    
    echo 'Mohanlal acted ' . $numberOfMovies .' in last 2 years';
    
    
    echo '<br>';
    
    
    
    
    $mohanlalHitMovies = array('Drishyam', 'Narasimham', 'Aaram Thampuran', 'Spadikam', 'Thenmavin Kombathu', 'Manichithrathazhu', 'Devasuram', 'Kilukkam', 'Chithram', 'Irupatham Noottandu');
    
    
    $numberOfHitMovies = count($mohanlalHitMovies);
    
    
    echo 'Mohanlal has ' . $numberOfHitMovies . ' All Time Record Blockbustors';

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

    Default

    DAY 5 PHP PROGRAMMING

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

    Code:
    <?php
    
    
    $mohanlalHitMovies = array('Mr. Fraud', 'Drishyam', 'Geethanjali', 'Red Wine', 'Ladies and Gentleman', 'Lokpal', 'Karmayodha', 'Run Baby Run', 'Spirit', 'Grandmaster', 'Casanova');
    
    
    foreach($mohanlalHitMovies as $mohanlalMovies) {
    
    
    echo $mohanlalMovies;
    
    
    echo '<br>';
    
    
    }

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

    Default

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

    Code:
    <?php
    
    // create array
    
    $vegetables = array('tomato', 'potato', 'cucumber', 'carrot', 'spinach', 'cabbage', 'chilli');
    
    // lets print
    
    echo '<pre>';
    
    print_r($vegetables);
    //var_dump($vegetables);
    
    echo '</pre>';

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

    Default

    Quote Originally Posted by sherlyk View Post
    http://php.flashwebhost.com/sherly/Vegetables0.php
    Code:
    <?php
    
    // create array
    
    $vegetables = array('tomato', 'potato', 'cucumber', 'carrot', 'spinach', 'cabbage', 'chilli');
    
    // lets print
    
    echo '<pre>';
    
    print_r($vegetables);
    //var_dump($vegetables);
    
    echo '</pre>';
    Good, keep file names always smaller cause as a standard.
    Become PHP Expert in 30 days
    FreeMarriage.com - Free Online Matrimonial
    FlashWebHost.com - Professional Web Hosting, Designing.

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

    Default

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

    Code:
     <?php
    
    // create array
    
    $vegetables = array('tomato', 'potato', 'cucumber', 'carrot', 'spinach', 'cabbage', 'chilli');
    
    $numberOfVegetables= count($vegetables);
    
    echo '<p>We have ' . $numberOfVegetables . ' fresh vegetables in our store.</p>';

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
  •