Results 1 to 10 of 42

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

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #14
    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.

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
  •