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

  • SEARCH
  • Home
  • 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 8857671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:38:53+00:00 2026-06-14T14:38:53+00:00

how does the performance of a FOR loop compare to that of a FOREACH

  • 0

how does the performance of a FOR loop compare to that of a FOREACH / WHILE / DO WHILE itation construct in PHP?

  • 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. Editorial Team
    Editorial Team
    2026-06-14T14:38:54+00:00Added an answer on June 14, 2026 at 2:38 pm

    Even if there is any kind of difference, that difference will be so small it won’t matter at all.

    If you have, say, one query to the database, it’ll take so long compared to the loop iterating over the results that the eternal debate of for vs foreach vs while vs do will not change a thing — at least if you have a reasonable amount of data.

    So, use :

    • whatever you like
    • whatever fits your programming standard
    • whatever is best suited for your code/application

    There will be plenty of other things you could/should optimize before thinking about that kind of micro-optimization.

    And if you really want some numbers (even if it’s just for fun), you can make some benchmark and see the results in practice.

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

Sidebar

Related Questions

Does defining functions inside a loop affect performance? Like var doSomething = function(element){ $(element).whatever();
Does loop unrolling effect data cache performance in any way? This is related to
Possible Duplicate: What loop is faster, while or for I see in three.js that
Does it hurt in performance when I loop through list-items and add a click-handler
I have a do...while loop and a try...catch block that wraps around database centric
Does performance of a database (SQL Server 2005) decrease if I shrink it? What
How does performance for reading/adding values from/to Dictionary(Of String, SomeReferenceType) depend on the number
I guess you already know the question ;) Does the performance wizard only exist
Does windows have performance counters to measure statistics of a dialup connection? Opening up
What is the purpose of using the Boost.MPI library? Does it increase performance? And

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.