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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:40:28+00:00 2026-06-08T16:40:28+00:00

I have the following code in a website. $magic_number_output = ‘The magic number is:

  • 0

I have the following code in a website.

$magic_number_output = 'The magic number is: $magic_number';

function show_magic_number($magic_number) {
  global $magic_number_output;

  eval("\$magic_number_output = \"$magic_number_output\";");

  echo '
  ' . $magic_number_output;

}

The variable $magic_number_output is being set in a separate PHP file, then referenced using global inside a function as there will be different versions of this variable for different languages. $magic_number is passed into the function and this is replaced in the variable by using eval(). However, when the function is called more than once, the $magic_number does not change from the first value sent to the function. For example, if called like this:

show_magic_number(5);
show_magic_number(2000);

…the output is like this:

The magic number is: 5
The magic number is: 5

…when I would like it to be this:

The magic number is: 5
The magic number is: 2000

Obviously, I’ve misunderstood how global and eval() works and have tried searching for answers and experimenting but am simply too much of a noob to figure out a solution. I thought there might have been some way of resetting the global variable each time so that it doesn’t continue to reference the $magic_number (i.e. 5) sent to the function the first time.

Can anyone suggest a way around this?

  • 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-08T16:40:29+00:00Added an answer on June 8, 2026 at 4:40 pm

    Try this. It will at least get rid of the eval()

    $magic_number_output = 'The magic number is: $magic_number';
    
    function show_magic_number($magic_number) {
      global $magic_number_output;
    
      $output=$magic_number_output;
      echo str_replace('$magic_number',$magic_number,$output);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: String website = http://www.somewebsite.com/; Document doc = Jsoup.connect(website).get(); Elements
I have a internal website hosted on IIS. I added the following meta code
I have the following code on my website, which basically checks to see if
I have the following code, which is a modified version from MSDN's website, to
I have following code in html file: <html> <head> <title>My Great Website</title> </head> <body>
I have the following code below on my website. It's used to find the
I have the following code in the header of a website that I'm working
I currently have the following code for EVERY page on my website. Please could
I have the following code on my website: <?php $loggedout = $_GET[loggedout]; if ($loggedout==true)
I have seen the following code in a website... what does this mean?.Can i

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.