end()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • The Plankmeister

    #1

    end()

    The following code always prints 45, not "Humpty Dumpty". But in the
    documentation for end() this behaviour is not specified when passed an
    associative array. I'm assuming that end() behaves this way in all versions
    of PHP?

    $test = array("Fred" => 12, "Bill" => 23, "Bob" => 34, "Humpty Dumpty" =>
    45);
    echo end($test);


  • Pedro Graca

    #2
    Re: end()

    The Plankmeister wrote:[color=blue]
    > The following code always prints 45, not "Humpty Dumpty". But in the
    > documentation for end() this behaviour is not specified when passed an
    > associative array. I'm assuming that end() behaves this way in all versions
    > of PHP?
    >
    > $test = array("Fred" => 12, "Bill" => 23, "Bob" => 34, "Humpty Dumpty" =>
    > 45);
    > echo end($test);[/color]

    This is according to the documentation.

    Your line $test = array(...) is the same as

    unset($test);
    $test['Fred'] = 12;
    $test['Bill'] = 23;
    $test['Bob'] = 34;
    $test['Humpty Dumpty'] = 45;

    end() returns the value of the last element of the array;
    the last element of $test is $test['Humpty Dumpty'] and its value is 45.
    --
    --= my mail box only accepts =--
    --= Content-Type: text/plain =--
    --= Size below 10001 bytes =--

    Comment

    Working...