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
passing an array to a function by reference
Moderator: General Moderators
which version of php? what os?
What are you trying to do?

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);
?>just as expectedArray ( [0] => 1 [1] => 0 )
Syntax error
Thanks a lot. And sorry about the post.
I was in a syntax error.
I was in a syntax error.