Convert PHP code into Ruby!
RSS icon Email icon Home icon
  • array_shift

    Posted on October 14th, 2009 RubyLove No comments

    The array_shift() function in PHP removes an element from the beginning of an array and returns it.

    PHP

    $my_array = array('a', 'b', 'c', 'd');
    $my_element = array_shift($my_array);
    print_r($my_element);
    /*
    Array (
    	[0] => a
    )
    */

    Ruby

    my_array = [ "a", "b", "c", "d" ];
    puts my_array.shift;
    # => ["a"]

    Leave a reply