Page 3 of 5 FirstFirst 12345 LastLast
Results 21 to 30 of 42

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

  1. #21
    Join Date
    Nov 2009
    Posts
    76,596

    Default

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

    Code:
    <?php
    
    $vegetables = array('tomato', 'potato', 'cucumber', 'carrot', 'spinach', 'cabbage', 'chilli');
    
    
    echo '<pre>';
    print_r($vegetables );
    echo '</pre>';
    
    echo '<p>I am going to add 2 more vegetables  to $vegetables  array.</p>';
    
    $vegetables [] = 'beetroot';
    $vegetables [] = 'beans';
    
    echo '<pre>';
    print_r($vegetables );
    echo '</pre>';

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

    Default

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


    Code:
    <?php
    
    
    $sports = array('FootBall', 'Cricket', 'Hockey', 'basketball', 'Golf', 'rugby', 'Baseball');
    
    
    echo $sports[0];
    echo '<br>';
    echo $sports[1];
    echo '<br>';
    echo $sports[6];
    echo '<br>';
    echo $sports[2];
    echo '<br>';

    Nice program, try other examples too.
    Become PHP Expert in 30 days
    FreeMarriage.com - Free Online Matrimonial
    FlashWebHost.com - Professional Web Hosting, Designing.

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

    Default

    Quote Originally Posted by sherlyk View Post
    http://php.flashwebhost.com/sherly/age2.php

    Code:
    <?php
    $age=array('Susan', 'Jane','Anne');
    echo 'My Best friends are ';
    
    // lets print
    
    echo $age[0];
    echo '<br>';
    echo $age[1];
    echo '<br>';
    echo $age[2];
    Why do you store friends in an array $age ?

    Follow naming convention, use meaningful names for variables. Don't store friends in $enemy array, they can get attacked by mistake.
    Become PHP Expert in 30 days
    FreeMarriage.com - Free Online Matrimonial
    FlashWebHost.com - Professional Web Hosting, Designing.

  4. #24
    Join Date
    Apr 2005
    Posts
    46,704

    Default

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

    Code:
    <?php
    
    $cars = array ('Ferrari', 'Ford' ,'Dodge','Honda', 'Hyundai', 'Nissan');
    
    echo '<pre>';
    print_r ($cars);
    
    
    echo '<p>  I am going to add to 3 more cars to $cars array. </p>';
    
    $cars[] = 'Mercedes';
    $cars[] = 'Toyota';
    $cars[] = 'Tata';
    
    echo '<pre>';
    print_r ($cars);
    echo '<pre>';

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

    Default

    Quote Originally Posted by minisoji View Post
    http://php.flashwebhost.com/mini/elements.php

    Code:
    <?php
    
    $cars = array ('Ferrari', 'Ford' ,'Dodge','Honda', 'Hyundai', 'Nissan');
    
    echo '<pre>';
    print_r ($cars);
    
    
    echo '<p>  I am going to add to 3 more cars to $cars array. </p>';
    
    $cars[] = 'Mercedes';
    $cars[] = 'Toyota';
    $cars[] = 'Tata';
    
    echo '<pre>';
    print_r ($cars);
    echo '<pre>';
    Good code.
    Become PHP Expert in 30 days
    FreeMarriage.com - Free Online Matrimonial
    FlashWebHost.com - Professional Web Hosting, Designing.

  6. #26
    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>';

  7. #27
    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>';

  8. #28
    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.

  9. #29
    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];

  10. #30
    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>';

Page 3 of 5 FirstFirst 12345 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
  •