array_reverse

  • We can reverse an array in Ruby using the Array#reverse method.

    PHP

    $fruit = array('apple', 'banana', 'kiwi');
    $result = array_reverse($fruit);
    var_export($result);
    // => array(0 => 'kiwi', 1 => 'banana', 2 => 'apple')

    Ruby

    fruit = ["apple", "banana", "kiwi"]
    p fruit.reverse
    # => ["kiwi", "banana", "apple"]

    see also

Looking for Rails or PHP web application development, integration, and training?

Rails for PHP is brought to you by Maintainable Software. Get custom web applications and personalized training from the authors of the book and website.