Page 2 of 5 FirstFirst 1234 ... LastLast
Results 11 to 20 of 42

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

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

    Default array_count exmple

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

    PHP Code:

    <?php 
    $family 
    = array('Father','Mother','Brother' 'Sister');
    $numberOfFamily count($family);
    echo 
    ' I have ' $numberOfFamily ' members in my family .';
    echo 
    '<br>';
    echo 
    $family[0];
    echo 
    '<br>';
    echo 
    $family[1];
    echo 
    '<br>';
    echo 
    $family[2];
    echo 
    '<br>';
    echo 
    $family[3];

  2. #12
    Join Date
    Sep 2003
    Location
    india
    Posts
    11,527

    Default

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

    Code:
    <?php
    
    $flowers = array('Jasmine','Rose','Orkid', 'Lotus');
    
    echo 'My Favourit Flowers are ' . $flowers[1] . ' and ' . $flowers[3]; 
    
    echo '<pre>';
    print_r($flowers);
    echo '</pre>';


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

    Code:
    <?php
    
    $states = array('Alappuzha', 'Ernakulam', 'Thiruvanthapuram', 'Kollam', 'Palakkad');
    
    $numberOfStates = count($states);
    echo '<pre>';
    print_r($states);
    
    echo '<p> I am going to add 2 more states to $states array. </p>';
    
    $states[] = 'Kottayam';
    $states[] = 'Kannur';
    
    echo '<pre>';
    print_r ($states);
    echo '</pre>';

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

    Default Foreach Examples

    http://php.flashwebhost.com/sibichan...ch-example.php

    PHP Code:
    <?php
    $vechicles
    = array ('Bus' 'Car' 'Van' 'Auto');
    foreach (
    $vechicles as $vechicle) {
    echo 
    $vechicle;
    echo 
    '<br>';
    }
    Another Example for foreach

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

    PHP Code:


    <?php
    $networkingSites 
    = array('Facebook' 'Twitter' 'Pinterest' 'Delicious' );
    foreach (
    $networkingSites as $networkingSite) {
    echo 
    $networkingSite;
    echo 
    '<br>';
    }
    Last edited by Vahaa11; 05-14-2014 at 07:25 AM.

  4. #14
    Join Date
    Nov 2009
    Posts
    76,596

    Default

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

    Code:
    <?php
    
    $subjects = array('Malayalam', 'Hindi', 'Maths', 'scinece');
    
    echo 'My Favourite Subjects are ' . $subjects[1] . 'and ' . $subjects[4];
    
    echo '<pre>';
    print_r($subjects);
    echo '</pre>';

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

    Default

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

    Code:
    <?php
    
    $mystudents = array('Neena' , 'Meera' , 'Leena' , 'Zeena' );
    foreach ($mystudents as $mystudents) {
    echo $mystudents;
    echo '<br>';
    }

  6. #16
    Join Date
    Apr 2005
    Posts
    46,704

    Default

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


    Code:
    <?php
    
    
    $animals = array('lion', 'dog', 'cat', 'horse', 'rabit', 'tiger', 'rabit', 'camel', 'deer', 'fox', 'squirrel');
    
    echo $animals[0];
    echo '<br>';
    echo $animals[2];
    echo '<br>';
    echo $animals[3];
    echo '<br>';
    echo $animals[5];
    echo '<br>';
    echo $animals[10];

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

    Default Array add example

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

    PHP Code:

    <?php $hostingPackage = array (' Small '' Medium ' ' Large ') ;
    echo 
    '<pre>';

    print_r($hostingPackage);

    echo 
    '</pre>';

    $hostingPackage [] = 'Premium';$hostingPackage [] = 'Starandard';

    echo 
    '<pre>';

    print_r($hostingPackage);echo '</pre>';
    Another example

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


    PHP Code:
    <?php 
    $companyNames 
    = array('BizHat''FlashWebHost''HostOnNet');
    echo 
    '<pre>';

    print_r($companyNames);

    echo 
    '</pre>';
    echo 
    'Iam going to add 2 more Company Names';
    echo 
    '<br>';
    $companyNames[] = 'Buyscripts';
    $companyNames[]= 'FreeMarriage';
    echo 
    '<pre>';

    print_r($companyNames);

    echo 
    '</pre>';
    Last edited by Vahaa11; 05-14-2014 at 08:59 AM.

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

    Default

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

    Code:
    <?php
    
    $states = array('Kerala' , 'Tamil Nadu' , 'Karnataka' , 'Rajastan' , 'Orissa' );
    
    $numberOfStates = count($states);
    echo '<pre>';
    print_r($states);
    
    echo '<p> I am going to add 2 more states to $states array. </p>';
    
    $states[] = 'Kerala';
    $states[] = 'Tamil Nadu';
    
    echo '<pre>';
    print_r ($states);
    echo '</pre>';
    Last edited by sherlyk; 05-14-2014 at 09:33 AM.

  9. #19
    Join Date
    Nov 2004
    Location
    India
    Posts
    65

    Default

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

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

    Default

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


    Code:
    <?php
    
    
    $states = array('Kerala' , 'Tamil Nadu' , 'Karnataka' , 'Rajastan' , 'Orissa' );
    
    
    $numberOfStates = count($states);
    echo '<pre>';
    print_r($states);
    
    
    echo '<p> I travelled  to add 2 more states to $states array. </p>';
    
    
    $states[] = 'Kerala';
    $states[] = 'Tamil Nadu';
    
    
    echo '<pre>';
    print_r ($states);
    echo '</pre>';

    Modified your code like below. Try to create meaningfull sentences.


    Your are not using the count(); function. Then no need to add in your script. Right ?


    PHP Code:

    <?php

    $states 
    = array('Kerala' 'Tamil Nadu' 'Karnataka' 'Rajastan' 'Orissa' );

    $numberOfStates count($states);

    echo 
    '<pre>';

    print_r($states);

    echo 
    '<pre>';

    echo 
    $numberOfStates ' States are listed here.I am going to add 2 more states ' ;

    $states[] = 'Gujarat';

    $states[] = 'Maharashtra';

    echo 
    '<pre>';

    print_r ($states);

    echo 
    '</pre>';

    echo 
    'So the total no of states  ' $numberOfStates;
    Last edited by Vahaa11; 05-14-2014 at 11:16 AM.

Page 2 of 5 FirstFirst 1234 ... 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
  •