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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:23:00+00:00 2026-06-06T18:23:00+00:00

$cars = array( array(‘name’ => ‘Toyota’, price => 10000, …), array(‘name’ => ‘Ford’, price

  • 0
$cars = array(
     array('name' => 'Toyota', price => 10000, ...),
     array('name' => 'Ford', price => 20000, ...),
     ...
);

foreach($cars as &$car)
{
   do_something($car['name']);
}
unset($car);

function do_something($name)
{
    ....
}

In do_something() function, is $name a reference or a value? If it is a reference, how do I just retrieve the value in the loop and pass that in the function?

  • 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-06T18:23:02+00:00Added an answer on June 6, 2026 at 6:23 pm

    No, $name in do_something() function is not a reference, it is not pass by reference, only pass the value of $car['name'] to $name.

    If you want to pass by reference, you could do like below, pass $car as reference.

    $cars = array(
         array('name' => 'Toyota', price => 10000),
         array('name' => 'Ford', price => 20000)
    );
    
    foreach($cars as &$car)
    {
       do_something($car);
    }
    
    var_dump($cars);
    
    function do_something(&$car)
    {
        $car['name'] .= '_changed';
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having this php code: $data['items'] = array('cars', 'bikes', 'trains'); $data['title'] = $parameters['title']; foreach ($searchResults
I have a large array in this format: var cars = [{brand:Honda,year:2002},{brand:Toyota,year:2000},{brand:Subaru,year:2009}]; The array
I'm using multi-dimensional input tags in my html: Car 1 <input name=warehouse[cars][][name] /> <input
I have Car (table cars ) method that has_many owners (table owners ). How
I created a method to swap the cars from the owners. bool owner::changeCar(owner& other,
I have an array for all the cars in a online game I'm making
I have an array of Car objects I want to conver them to a
I have an array that looks something like this array( 'cars' => 10, 'trucks'
I have this class JobsController extends EncoderAppController { var $uses = array('Cars.Engine','Trucks', 'TruckModel', 'Cars.Properties'
In spinner xml, I'm using: android:entries=@array/cars where cars is list of numeric items. The

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.