passing an array to a function by reference

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Alberto
Forum Newbie
Posts: 2
Joined: Sat Apr 19, 2003 6:48 pm

passing an array to a function by reference

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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 ;)
Alberto
Forum Newbie
Posts: 2
Joined: Sat Apr 19, 2003 6:48 pm

Syntax error

Post by Alberto »

Thanks a lot. And sorry about the post.

I was in a syntax error.
Post Reply