current
-
Ruby has no internal pointer in array objects like PHP. Because of this, there is no direct equivalent to PHP’s
current function.Sometimes
currentis used to grab the first value of an array. We can do this in Ruby using theArray#firstmethod.PHP
$fruit = array('apple', 'orange'); $result = current($fruit); var_export($result); // => 'apple'
Ruby
fruit = ["apple", "orange"] result = fruit.first # => "apple"
The
firstmethod does not work for associative key/value hashes in Ruby since hashes are unordered collections.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.

