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

    Posted on October 10th, 2009 RubyLove No comments

    The array_unique() function in PHP takes an array and filters our any duplicates values, returning the array with only unique values present.

    PHP

    $elements = array('php', 'ruby', 'perl', 'php');
    array_unique($elements);
    print_r($elements);
    /*
    Array (
    	[0] => php
    	[1] => ruby
    	[2] => perl
    )
    */

    Ruby

    elements = [ "php", "ruby", "perl", "php" ];
    puts elements.uniq;
    # => ["php", "ruby", "perl"]

    Leave a reply