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 :: causes of 419 error lravel 
Php :: download speed limit php 
Php :: remove link from product name in woocommerce cart 
Php :: insert php variable css 
Php :: update json file php 
Php :: strlen php 
Php :: php function to convert string to camelcase 
Php :: php remove specific element from array 
Php :: how to get value of textarea in php 
Php :: get original name without mutant model laravel 
Php :: Convert Carbon Seconds Into Days Hours Minute 
Php :: default index page for laravel in cpanel 
Php :: array push foreach php 
Php :: wordpress get user id by email 
Php :: overwrite file php 
Php :: laravel migration change column length 
Php :: php check if associative array is null 
Php :: concat() function using laravel eloquent query 
Php :: remove .php from url 
Php :: codeigniter 4 redirect to home 
Php :: create user with tinker php laravel 
Php :: get category post in wordpress 
Php :: use class Auth larave3l 
Php :: php if string contains 
Php :: laravel check if table has column 
Php :: console log in php 
Php :: post type taxonomy loop wordpress 
Php :: php echo 
Php :: php routing 
Php :: string to int php 
ADD CONTENT
Topic
Content
Source link
Name
9+2 =