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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:25:15+00:00 2026-05-25T18:25:15+00:00

Hey is this the correct way to do concatenation? it does not seem to

  • 0

Hey is this the correct way to do concatenation? it does not seem to want to work for me!.

        $driver1points = 0;
        $driver2points = 0;
        $driver3points = 0;
        $driver4points = 0;

        for($i = 1; $i <= 4; $++){
            if(${"driver".$i} == $driverrace["fastestlap"]) {
                ${"driver". $i ."points"} += $driver_points_system["fastestlap"];
                $racepoints += $team_points_system["fastestlap"];
                break;
            }
         }
  • 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-25T18:25:16+00:00Added an answer on May 25, 2026 at 6:25 pm

    I agree with what is said in the comments. An array is a much better way to handle this.

    <?php
    $driver1points = 0;
    $driver2points = 0;
    $driver3points = 0;
    $driver4points = 0;
    
    for($i = 1; $i <= 4; $++) {
        $driver = "driver$i";
        if($$driver == $driverrace["fastestlap"]) {
            ${$driver."points"} += $driver_points_system["fastestlap"];
            $racepoints += $team_points_system["fastestlap"];
            break;
        }
    }
    

    Can be translated into:

    <?php
    $drivers['bill']   = 0;
    $drivers['ted']    = 0;
    $drivers['cheech'] = 0;
    $drivers['chong']  = 0;
    
    foreach ( $drivers as $driver => &$points ) {
        if ( $driver == $race['fastestlap'] ) {
            echo "$driver had the fastest lap!";
            $points     += $driver_points_system['fastestlap'];
            $racepoints += $team_points_system['fastestlap'];
            break;
        }
    }
    

    You can obviously do this as a numerative array and replace all of the $drivers[$driverName] assignments to just $drivers[]. I used an associative array to demonstrate that arrays are not only more efficient for this application, they can also be much easier to work with.

    I passed the value argument of the foreach by reference, the “&” prefix (similar to a pointer, variable stores the memory address as opposed to the value); this allows you to directly manipulate the value in your logic as opposed to being given a copy of the value and needing to reassign with something similar to a $drivers[$driver] = $points;

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

Sidebar

Related Questions

Hey guys I'm not sure how to phrase this to get the correct search,
Hey all, I am not quite getting why this doesn't seem to be working.
Hey I have this code but it doesn't work because it is expecting a
hey guys m having this wierd exception of cast though my datatypes are correct
Possible Duplicate: Form validation Hey all, I'm just looking for what the correct way
Hey all, I've seen a lot of topics on this, but not quite what
Hey this is going to be one of those dumb questions. I am trying
Hey This is my login script, using PHP5 and MYSQLi, I just had help
Hey i have this div that shows as a popup: <div class=popup> </div> Then
Hey I have this code right here: http://pastie.org/534470 And on line 109 I get

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.