Skip to content

Instantly share code, notes, and snippets.

@nabeen
Created April 4, 2018 09:01
Show Gist options
  • Save nabeen/4725c3dbc5fd55f7066e8f4eb36cb5f3 to your computer and use it in GitHub Desktop.
Save nabeen/4725c3dbc5fd55f7066e8f4eb36cb5f3 to your computer and use it in GitHub Desktop.
use reference call in PHP
<?php
$data = range(1, 10);
print_r($data);
x2val($data);
print_r($data);
function x2val(&$data) {
foreach ($data as &$val) {
$val = $val * 2;
}
}
// output
// Array
// (
// [0] => 1
// [1] => 2
// [2] => 3
// [3] => 4
// [4] => 5
// [5] => 6
// [6] => 7
// [7] => 8
// [8] => 9
// [9] => 10
// )
// Array
// (
// [0] => 2
// [1] => 4
// [2] => 6
// [3] => 8
// [4] => 10
// [5] => 12
// [6] => 14
// [7] => 16
// [8] => 18
// [9] => 20
// )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment