Page 1 of 1

passing an array to a function by reference

Posted: Sat Apr 19, 2003 6:48 pm
by Alberto
Hello, I have been tring to pass an array to a function by reference, but I have no good results:

with the standar syntax:

function my_function(&$array_name)
{
....
}

I have no results: any modificatinons in the function don't persist.

Any solution? Thanks a lot

Posted: Sat Apr 19, 2003 7:37 pm
by volka
which version of php? what os?
What are you trying to do?

Code: Select all

<?php
function my_function(&$array_name)
{
	$array_name[] = $array_name[0]++;
} 

$arr = array(0);
my_function($arr);
print_r($arr);
?>
:arrow:
Array ( [0] => 1 [1] => 0 )
just as expected ;)

Syntax error

Posted: Sun Apr 20, 2003 11:48 am
by Alberto
Thanks a lot. And sorry about the post.

I was in a syntax error.