array_push

  • We can push additional elements to the end of an array in Ruby using the Array#push method.

    PHP

    $fruit = array('apple', 'banana');
    array_push($fruit, 'kiwi', 'lime');
    var_export($fruit);
    // => array(0 => 'apple', 1 => 'banana', 2 => 'kiwi', 3 => 'lime')

    Ruby

    fruit = ["apple", "banana"]
    fruit.push("kiwi", "lime")
    # => ["apple", "banana", "kiwi", "lime"]

    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.