is_array

  • We can check if a variable is an array in Ruby using Object#is_a?.

    PHP

    $colors = array('red', 'green', 'blue');
    $result = is_array($colors);
    var_export($result);
    // => true

    Ruby

    colors = ["red", "green", "blue"]
    p colors.is_a?(Array)
    # => true

    see also

is_a is_bool

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.