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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:26:08+00:00 2026-06-11T21:26:08+00:00

PHP Version 5.3.2-1ubuntu4.15 1st, starting values: $value_array = array(‘0.000′,’2.530’,8); $op_value = 2; Try this:

  • 0

PHP Version 5.3.2-1ubuntu4.15

1st, starting values:

$value_array = array('0.000','2.530',8);
$op_value = 2;

Try this:

            foreach($value_array as &$source_value) {
                $source_value = $source_value + $op_value;
            }

And get $value_array == (2,4.53,10);

But if you run this:

            array_walk($value_array,function(&$source_value) {
                $source_value = $source_value + $op_value;
            });

You get $value_array == (0,2.53,8);

The first one gives the expected result, the second one doesn’t. But it does do SOMEthing. The excess 0’s ended up getting chopped off.

Why is this? I wanted to use array_walk but now have to use foreach.

  • 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-11T21:26:09+00:00Added an answer on June 11, 2026 at 9:26 pm

    You can use the use declaration to access the outside variable:

            array_walk($value_array,function(&$source_value) use ($op_value) {
                $source_value = $source_value + $op_value;
            });
    

    or if it’s a global you can do:

            array_walk($value_array,function(&$source_value) {
                global $op_value;
                $source_value = $source_value + $op_value;
            });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using PHP Version 5.3.2-1ubuntu4.11 LibXML is enabled: dom DOM/XML enabled DOM/XML API
PHP version: 5.3.5 Apache version 2 OS: Windows Server 2008 R2 I am trying
PHP version 5.3 has been released, and although it looks great, all my code
I wanted the latest PHP version to work with on a fresh Macbook, but
As of PHP version 5.3 PDO_MYSQL driver has been repleaced in favour of PDO_MYSQLND
My server have default php version of 4, so when I run some script
I've downloaded memcache.php version 3.0.6 from there and out of the box (after defining
I am working with a PHP version the Pinterest Pin It button and I'm
I need to change upgrade the PHP version to at least 5.2.0 for my
I have Eclipse PDT version 1.3.0 PHP Version 5.3.8 Running on windows XP Pro

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.