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 6155061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:22:13+00:00 2026-05-23T20:22:13+00:00

Below I have a segment of my code that I recently added to my

  • 0

Below I have a segment of my code that I recently added to my PHP, which takes an array of integers ($naEUS) and iterates though it, appending the numbers with commas in between with a few exceptions for the start and finish. The end result should be a string that looks like this: ( ### , ### , ### , ### )

    $num = count( $naEUS[$f] );
    $resultsFields_values = "(";
    for( $b = 0; $b < $num; $b++ )
    {
        if( $b = 0 )
        {
            $resultsFields_values = substr_replace( $resultsFields_values, " {$naEUS[$b]} " , ( strlen($resultsFields_values) ), 0);
        }
        $resultsFields_values = substr_replace( $resultsFields_values, ", {$naEUS[$b]} " , ( strlen($resultsFields_values) ), 0);
    }
    $resultsFields_values = substr_replace( $resultsFields_values, ")" , ( strlen($resultsFields_values) ), 0);

I realize there are plenty of threads addressing string concatenation, but they only address part of my problem. I know this is a horribly inefficient way of doing this. and they show a better way of doing it, but that’s easy to find.

What I really want to know is why it took my 5 second run time PHP to it’s 30 second timeout.

Of course, better solutions are also welcome.

  • 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-05-23T20:22:14+00:00Added an answer on May 23, 2026 at 8:22 pm

    Well, it depends on the size of the array, but what you’re doing here is reallocating that string in every iteration using a rather inefficient function. This will probably work fine as long as your array is small, but when it contains a couple of thousands of items, it’s not wonder that execution takes long.

    A better solution would be to use the implode function, like this:

    $resultFields_values = '(' . implode(' , ', $naEUS) . ')';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm finalizing a code segment that lists the files in a directory. I have
I have the below query, which basically it retrieves the 5 top most books
I have the below code in stdafx.h. using namespace std; typedef struct { DWORD
The code I have pasted below is meant to display images on the middle
I am trying to learn more about regular expressions I have one below that
I have some code within one function that I want to separate into its
The code segment below prints out The types ARE NOT the same.. Why? I
Below i have pasted my piece of javascript code here 1) function showCustomerName(dropdown) {
I have an odd problem. When I try to compile the code below, it
I have XML as below which I am loading into XDocument <ConversionSpecification xmlns=http://tempuri.org/X12ParserSpecification.xsd TransactionSetIdentifierCode=837>

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.