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

    Posted on April 8th, 2009 RubyLove No comments

    Returns TRUE if the given argument is set in the array. The argument passed in can be any value possible for an array index.

    PHP

    $a = array('first' => 1, 'second' => 2);
    var_dump( array_key_exists('first', $a) );
    // => true

    Ruby

    animals = {:sheep => 1, :cow => 2};
    puts animals.include?(:cow);
    # => true

    Leave a reply