Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

php pass by reference

<?php
  
// Declair function assigns a new value to 
// $string variable and prints it
  function return_string( &$string ) {

    //build return string var
    $return_the_string = $string . "- returned STRING";

    //modify the string var
    $string = $string . "- passed byREF";

    // you could print or return the string aswell
    //print( $string );
    return $return_the_string ;
  }

// EXAMPLE 1 ----------------------
  $string = "1-Input string ";

  return_string( $string ); //call function

  print( $string ); //print string with new text

# EXAMPLE 1 OUTPUT:
  # 1-Input string - passed byREF 


// EXAMPLE 2 ----------------------
  $string = "2-Input string ";

  $returned_string = return_string( $string ); //call function

  print( $string); //print string with new text
  print( $returned_string ); //print string with new text

  # EXAMPLE 2 OUTPUT:
    # 2-Input string - passed byREF
    # 2-Input string - returned STRING

?> 
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #php #pass #reference
ADD COMMENT
Topic
Name
1+2 =