array_values

  • This function’s solution uses a Ruby Hash object since Ruby arrays don’t use associative key/value pairs. See Array for more details.

    To get the values of an associative hash in Ruby, we can use the Hash#values method.

    PHP

    $dinner = array('fruit' => 'apple', 'meat' => 'chicken');
    $result = array_values($dinner);
    var_export($result);
    // => array(0 => 'apple', 1 => 'chicken')

    Ruby

    dinner = {:fruit => "apple", :meat => "chicken"}
    p dinner.values
    # => ["apple", "chicken"]

    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.