PHP to Ruby
Convert PHP code into Ruby!
-
in_array
Posted on September 28th, 2009 No commentsThe in_array() function in PHP checks if a value exists in an array - returning true if it does, or false otherwise.
The last argument in this function forces a strict type check of the value in PHP. Since Ruby does not consider a Fixnum of 1 and a String of ‘1′ to be the same - it always operates as if the last argument were set to true.
PHP
$my_array = array('a', 'b', 'c', 'd'); if('a', in_array($a), true) { echo 'Found it in the array'; } // => Found it in the array
Ruby
my_array = [ "a", "b", "c", "d" ]; if( my_array.include?('a') ) { puts 'Found it in the array'; } # => Found it in the array
Leave a reply


