Linked Questions

14 votes
3 answers
25k views

Possible Duplicate: are arrays in php passed by value or by reference? I heard that PHP can select how to assign arrays, depends on array size. It can assign by copying value (as any scalar type) ...
RusAlex's user avatar
  • 8,645
0 votes
2 answers
6k views

Possible Duplicate: Are arrays or lists passed by default by reference in c#? I have read some contradicting posts on here about C# and whether arrays are passed by value or by reference. Could ...
CodeKingPlusPlus's user avatar
-2 votes
1 answer
124 views

I have a PHP class containing a 2-dimensional array: class ArrApp { private $cms = [ 'S' => 'A', 'V' => [] ...
SSteven's user avatar
  • 773
-2 votes
1 answer
140 views

If I have the following variable in a class protected $address and in a function test, I do $testAddress = $this->address; and then $testAddress['state'] = 'KO'; Does that change the state for $...
Kermit the Frog's user avatar
0 votes
1 answer
71 views

Consider the following code: class FOO { public $v = []; function &refv1() { return $this->v[1]; } function refv2(&$ref) { $ref = &$this->v[2]; } } $FOO = new FOO(...
rhavin's user avatar
  • 1,804
7743 votes
87 answers
2.8m views

I always thought Java uses pass-by-reference. However, I read a blog post which claims that Java uses pass-by-value. I don't think I understand the distinction the author is making. What is the ...
316 votes
16 answers
233k views

Are PHP variables passed by value or by reference?
cmcculloh's user avatar
  • 48.8k
21 votes
4 answers
29k views

I'm frequently using the following to get the second to last value in an array: $z=array_pop(array_slice($array,-2,1)); Am I missing a php function to do that in one go or is that the best I have?
zaf's user avatar
  • 23.4k
11 votes
1 answer
15k views

Is there a way in PHP to return a reference to an element in array? function ref(&$array, &$ref) { $ref = $array[1]; } $array = array(00, 11, 22, 33, 44, 55, 66, 77, 88, 99); ref($array, $ref)...
vbarbarosh's user avatar
  • 3,712
3 votes
2 answers
14k views

I'm having a hard time trying to update the values in my array. I made a simple example to illustrate this: the array contains names of players and the amount of points they have. After each round I ...
Roddeh's user avatar
  • 203
6 votes
4 answers
852 views

I have a JS function, with array inputs.For example: x=[ 239709880, 250229420, 109667654, 196414465, 13098 ] y=[ 78135241, 54642792, 249 ] OR: x=[ 0, 0, 0, 0, 0, 0, 1 ] y=[ 78135241, 54642792, 249 ]...
szmegma's user avatar
  • 249
9 votes
3 answers
2k views

I knew, that it can be dangerous to pass the items by reference in foreach. In particular, one must not reuse the variable that was passed by reference, because it affects the $array, like in this ...
Lorenz Meyer's user avatar
  • 20.1k
0 votes
2 answers
2k views

I was playing with PHP recently and wanted to assign variable in foreach loop and pass value by reference at the same time. I was a little bit surprised that didn't work. Code: $arr = array( 'one'...
Ness's user avatar
  • 1
1 vote
5 answers
436 views

I have a few arrays of strings like: $big = ['html', 'body', 'div', 'table', 'tbody', 'tr', 'td']; $small = ['body', 'div', 'td']; $wrong = ['td', 'body', 'div']; I need to check whether $small and $...
kaan_atakan's user avatar
  • 4,107
-4 votes
1 answer
1k views

Are arrays passed by reference or value in PHP? For example, let's see this code. function addWeight($arout, $lineCountry, $lineDomain, $target, $weight) { $currentDomain=getDomain(); $...
user4951's user avatar
  • 33.3k

15 30 50 per page