Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php pass variable by reference

<?php
  
function add_some_extra(&$string) {
    $string .= 'and something extra.';
}

$str = 'This is a string, ';
add_some_extra($str);

echo $str;    // outputs 'This is a string, and something extra.'

?>
Comment

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

?> 
Comment

PREVIOUS NEXT
Code Example
Php :: How to insert time in table using CodeIgniter 
Php :: laravel get session variable in controller 
Php :: laravel encrypt password 
Php :: composer clear cache 
Php :: blade foreach key value 
Php :: mac os change the php verison 
Php :: get key of value array php 
Php :: codeigniter 4 redirect to home 
Php :: php check if query returns results 
Php :: join cakphp 
Php :: how to take last entry in database in laravel Method ONe 
Php :: get category post in wordpress 
Php :: format datetime ISO php 
Php :: open php tag 
Php :: Calculate the Difference Between Two Dates Using PHP 
Php :: wpdb-prepare 
Php :: faker 
Php :: render vs redirect laravel exception 
Php :: left join in laravel 
Php :: how to get random element from a given array via php faker in laravel 
Php :: php remove element from array 
Php :: strpos in php 
Php :: laravel storage get file path 
Php :: wordpress show notice 
Php :: laravel where like 
Php :: php get current date strtotime 
Php :: php get data from prepared select 
Php :: wordpress hook add javascript 
Php :: make model with migration laravel 
Php :: php trim string if longer than 
ADD CONTENT
Topic
Content
Source link
Name
3+3 =