Program to swap two integer parameters using call by value & call by address in PHP ? Last Updated : 26 Apr, 2022 Comments Improve Suggest changes Like Article Like Report Call by value: In call by value, we will send the value from the calling function to the called function. The values of the calling function arguments are directly copied to the corresponding arguments of the called function. If any modification is done on the arguments of the called function, it will not be effected on the arguments of the calling function because the calling function arguments and the called function argument will be represented in different memory locations. Example: PHP <?php function sum($x) { $x = $x + 10; echo "The sum is $x<br>"; } // code $n = 20; sum($n); echo "</br>"; echo "value of n is $n"; ?> Output: The sum is 30 value of n is 20 Call by Reference: In the Call by reference mechanism, the address of a variable will be sent from the calling function to the called function. The corresponding addresses of the calling function arguments will be directly copied into the called function argument. Any modifications done to the called function arguments will be effected on the calling function arguments because both the arguments of the calling function and the called function represent the same memory location. Example: PHP <?php function sum(&$x) { $x = $x + 10; echo "The sum is $x"; } $n = 20; sum($n); echo"<br> value of n is $n"; ?> Output: The sum is 30 value of n is 30 Swapping of two numbers using call by value: PHP <?php function swap($x, $y) { $temp = $x; $x = $y; $y = $temp; echo "The value of x is:".$x."<br>"; echo "The value of y is:".$y."<br><br>"; } $a = 10; $b = 20; swap($a, $b); echo "The value of a is :".$a."<br>"; echo "The value of b is :".$b."<br>"; ?> Output: The value of x is:20 The value of y is:10 The value of a is :10 The value of b is :20 Swapping of two numbers using call by reference: PHP <?php function swap(&$x, &$y) { $temp = $x; $x = $y; $y = $temp; echo "The value of x is: ".$x."<br>"; echo "The value of y is: ".$y."<br><br>"; } $a = 10; $b = 20; swap($a, $b); echo "The value of a is: ".$a."<br>"; echo "The value of b is: ".$b."<br>"; ?> Output: The value of x is: 20 The value of y is: 10 The value of a is: 20 The value of b is: 10 Comment More infoAdvertise with us Next Article Program to swap two integer parameters using call by value & call by address in PHP ? S santhivicky143 Follow Improve Article Tags : Web Technologies PHP Similar Reads Javascript program to swap two numbers without using temporary variable To swap two numbers without using a temporary variable, we have multiple approaches. In this article, we are going to learn how to swap two numbers without using a temporary variable. Below are the approaches used to swap two numbers without using a temporary variable: Table of Content Using Arithme 6 min read PHP program to swap two numbers Integer values can be stored in a variable in PHP. It is easy to store and modify and swap these integer values using various mentioned approaches: Using a temporary variable: The value of the first number is stored in the temporary variable. This value is then replaced by the value of the second nu 4 min read Write a program to display Reverse of any number in PHP ? Write a program to reverse the digits of an integer. Examples : Input : num = 12345 Output: 54321 Input : num = 876 Output: 678 It can be achieved using Iterative way or Recursive Way Iterative Method: Algorithm: Input: num (1) Initialize rev_num = 0 (2) Loop while num > 0 (a) Multiply rev_num by 2 min read How to declare a function that receives one parameter in PHP ? In this article, we will know how to declare the function that receives the single parameter in PHP. Function calling is an important aspect of any programming language. Functions(methods) can be called within the script to simplify the performance of operations and eliminate the redundancy of writi 3 min read How to convert an Integer Into a String in PHP ? The PHP strval() function is used to convert an Integer Into a String in PHP. There are many other methods to convert an integer into a string. In this article, we will learn many methods.Table of ContentUsing strval() function.Using Inline variable parsing.Using Explicit Casting.Using sprintf() Fun 3 min read How to call PHP function from string stored in a Variable Given the names of some user-defined functions stored as strings in variables. The task is to call the functions using the names stored in the variables. Example: php <?php // Function without argument function func() { echo "geek"; } // Function with argument function fun($msg) { echo 2 min read Output of PHP programs | Set 3 Predict the output of below PHP programs: Question 1 PHP <?php $number = array(0, 1, one, two, three, 5); $num = preg_grep("/[0-5]/", $number); print_r($num); ?> Options: Array([0]=>0 [1]=>1 [2]=>one [3]=>two [4]=>three [5]=>5) Array([2]=>one [3]=>two [4]=> 3 min read How to Switch the First Element of an Arrays Sub Array in PHP? Given a 2D array where each element is an array itself, your task is to switch the first element of each sub-array with the first element of the last sub-array using PHP.Example:Input: num = [ ['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i']];Output: [ ['g', 'b', 'c'], ['d', 'e', 'f'], ['a', 'h', ' 2 min read PHP | ReflectionParameter __toString() Function The ReflectionParameter::__toString() function is an inbuilt function in PHP which is used to return the string form of the specified parameter. Syntax: string ReflectionParameter::__toString ( void ) Parameters: This function does not accept any parameters. Return Value: This function returns the s 2 min read ArrayObject exchangeArray() function in PHP The exchangeArray() function of the ArrayObject class in PHP is used to exchange an array from an ArrayObject. That is, it replaces existing array from an ArrayObject with a newly described array. Syntax: ArrayObject exchangeArray( $inputArray ) Parameters: This function accepts a single parameter $ 2 min read Like