Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 76365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T20:39:43+00:00 2026-05-10T20:39:43+00:00

PHP, for all its warts, is pretty good on this count. There’s no difference

  • 0

PHP, for all its warts, is pretty good on this count. There’s no difference between an array and a hash (maybe I’m naive, but this seems obviously right to me), and to iterate through either you just do

foreach (array/hash as $key => $value) 

In Ruby there are a bunch of ways to do this sort of thing:

array.length.times do |i| end  array.each  array.each_index  for i in array 

Hashes make more sense, since I just always use

hash.each do |key, value| 

Why can’t I do this for arrays? If I want to remember just one method, I guess I can use each_index (since it makes both the index and value available), but it’s annoying to have to do array[index] instead of just value.


Oh right, I forgot about array.each_with_index. However, this one sucks because it goes |value, key| and hash.each goes |key, value|! Is this not insane?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T20:39:44+00:00Added an answer on May 10, 2026 at 8:39 pm

    This will iterate through all the elements:

    array = [1, 2, 3, 4, 5, 6] array.each { |x| puts x }  # Output:  1 2 3 4 5 6 

    This will iterate through all the elements giving you the value and the index:

    array = ["A", "B", "C"] array.each_with_index {|val, index| puts "#{val} => #{index}" }  # Output:  A => 0 B => 1 C => 2 

    I’m not quite sure from your question which one you are looking for.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 88k
  • Answers 88k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer My answer in the other question does handle multiple levels… May 11, 2026 at 5:43 pm
  • Editorial Team
    Editorial Team added an answer Here's a script that creates a new user and gives… May 11, 2026 at 5:43 pm
  • Editorial Team
    Editorial Team added an answer Ok, I found out an official explanation from Symantec on… May 11, 2026 at 5:43 pm

Related Questions

PHP, for all its warts, is pretty good on this count. There's no difference
Is there Anyone that has experience with any open source, or relatively cheap voice
I've got a PHP script that needs to invoke a shell script but doesn't
We have a client (who has a client, who has a client) who is
Leading on from my previous questions I am going to try and clarify one

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.