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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:52:18+00:00 2026-05-27T20:52:18+00:00

<?php function f(& $var){$var = rand(); return $var;} echo f($var =a_).'<br/>’; /* outpu a

  • 0
<?php
function f(& $var){$var = rand(); return $var;}
echo f($var ="a_").'<br/>'; /* outpu a random number */
echo $var.'<br/>'; /*but don't change global variables, it still is "1<br/>", no the same like up line */
echo f($var).'<br/>'; /* outpu a random number */
echo $var.'<br/>'; /* haved change, the same like up line */
?>

run up code and output text like under block

28486
a_
25863
25863

Wwhy can’t change the $var in the first call?

<?php
function f(& $var, & $isRefer){$var = rand(); global $gVar; var_dump(array('are they same?' => $isRefer === $gVar)); return $var;}
$gVar = 'global var';
echo f($var ="a_", $gVar = & $gVar).'<br/>'; /* outpu a random number */
echo $var.'<br/>'; /*but don't change global variables, it still is "1<br/>", no the same like up line */
echo f($var, $gVar).'<br/>'; /* outpu a random number */
echo $var.'<br/>'; /* haved change, the same like up line */
?>

-the code output like-

array(1) {
[“are they same?”]=>
bool(true)
}
14802
a_
array(1) {
[“are they same?”]=>
bool(true)
}
19107
19107

so i think it is pass value like f($var = 'd') by “refer”

  • 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-27T20:52:19+00:00Added an answer on May 27, 2026 at 8:52 pm

    Passing variables by reference is a special case of function calling. Typically only the value of an expression is passed into the function as parameter.

    f(3 * 4);
    

    Here 3 * 4 is an expression that evaluates to 12, so 12 is passed into the function. A function that expects variables to be passed by reference though is different, because it needs a variable:

    function f(&$var) { ... }
    

    The purpose of passing by reference is to be able to modify the passed variable, not just a value. As such, you need to actually pass it a variable, not just a value. Calling the function with something like f(3 * 7) doesn’t make much sense in this case. Well, f($var = 'foo') is the same thing. $var = 'foo' is an expression, it’s not simply a variable. Therefore only the result of the expression (the value) is passed, not any variable that happens to appear in the expression.

    To illustrate that better, which variable should be passed when doing f($foo + $bar)? The answer is that it just doesn’t work that way. To pass a variable by reference, you can only use a variable as the parameter, not an expression.

    f($var);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

function check(id){ var _id = document.getElementById(id); url = test.php?check=1&id= + _id; } i want
<?php class Box { var $contents; function Box($contents) { $this-&gt;contents = $contents; } function
Is there a php function to handle the encodings below? .replaceAll(\u00c3\u0080, &Agrave;) .replaceAll(\u00c3\u0081, &Aacute;)
I have a javascript function generateGraph() { ... jQuery.get('chart.php?month='+month+'&year='+year); document.getElementById('graph').src = 'charts/'+month+'_'+year+'.png'; ... }
I have the following scenario jQuery('#content').fadeOut('slow',function(){ jQuery('#content').load(detail.php?product=+imgID+&category=+cat); jQuery('#content').fadeIn('fast'); }); My problem however is that
$.ajax({ method: post , url: save.php , data: id=453&action=test , beforeSend: function(){ } ,
edited: This is what i need: sendpost = function(a,b,c){ return jQuery.post('inc/operations.php', {a:b}, c, json);
$(document).ready(function(){ //global vars var name = $(#username); var email = $(#email); function usernameExists() {
I've made jQuery & AJAX script that uses a PHP function to bring back
Is the a proper php function to echo javascript string? I want to 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.