Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to point last element of an array in PHP?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 421
    Comment on it

    Hello friends,

    Today, we will learn how to get the last element of an array using PHP. There are various ways of doing it which are as follows:

    1. end(): PHP proivdes an in-built function which returns the last  element of an array end().

    Syntax:

    end ( $array )

    $array is the array whose last element needed to find out.

    Example:

    <?php
    $d = array('a', 'b', 'c');
    echo end($d);
    ?>

    It will return c.

    2. Next way is to count array elements and then decrement it by 1 as follows:

    <?php
    $d = array('a', 'b', 'c');
    echo end($d);
    echo $d[sizeof($d)-1];
    ?>

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: