C# - By Reference

using System;
					
public class Program
{
	public static void Main()
	{
		int[] scores = new int[]{1, 2, 3, 4};
		Console.WriteLine("Before");
		Print(scores);
		DoubleScores(scores);
		Console.WriteLine("After");
		Print(scores);
	}
	
	static void DoubleScores(int[] scores){
		for(int i = 0; i < scores.Length; i++){
			scores[i]*=2;
		}
	}
	
	static void Print(int[] a){
		foreach(int n in a)Console.WriteLine(n);
	}
}

Ouput of the above
Before
1
2
3
4
After
2
4
6
8

As you can see, array values were modified in place. If the function was working with a clone of the array, before and after would have been the same

PHP - By Reference unless you say otherwise


//default mode is by value
function printLine($scores){
	foreach($scores as $n)echo($n . "\n");
}

function doubleScores($scores){
	for($i =0; $i < sizeof($scores); $i++){
		$scores[$i] *= 2; 
	}
}
$scores = [1, 2, 3, 4];

echo("Before\n");
printLine($scores);
doubleScores($scores);
echo("After\n");
printLine($scores);

Output from above is

Before
1
2
3
4
After
1
2
3
4

To pass by value change the function definition from

 function doubleScores($scores) => function doubleScores(& $scores)
Note the amphersand before the scores parameter.

Then the result will become
Before
1
2
3
4
After
2
4
6
8

JavaScript - By reference

let scores = [1, 2, 3, 4];
console.log("Before");
console.log(scores);
doubleScores(scores);
console.log("After");
console.log(scores);

function doubleScores(scores){
  for(let i = 0; i < scores.length; i++){
    scores[i] *= 2;
  }
}

Output is
Before
(4) [ 1, 2, 3, 4]
After
(4) [ 2, 4, 6, 8]

I hope you find this helpful

Article image based on the Image by Gerd Altmann from Pixabay Image by Steve Bidmead from Pixabay