FW: Passing arrays by reference

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thanks,  That seems to have worked.  Now, can you or someone tell me why I
can't seem to get it to work when I separate the function implementation
from the calling statemtent?   For instance:


Say I have the following function in file called "My_Function_Includes.php":
<?php

function foo(&$a)
{
	for ($i=0; $i < 10; $i++)
	{
	    $a[$i] = $i;
	}
}
?> 

In my index.php I have:

<?php
Include_once('My_Function_Includes.php');

$a = array();

foo($a);

echo "<PRE>";
print_r($a);
echo "</PRE>";

?>


This example doesn't seem to work however, when I paste the function
implementation into the index.php and run it, it works. 


Thanks for any help in advance,
Jim


-----Original Message-----
From: Justin Patrin [mailto:papercrane@xxxxxxxxx]
Sent: Monday, August 09, 2004 5:52 PM
To: Jim MacDiarmid
Cc: php-windows@xxxxxxxxxxxxx
Subject: Re:  Passing arrays by reference

On Mon, 9 Aug 2004 17:28:40 -0400, Jim MacDiarmid
<jim.macdiarmid@xxxxxxxxxxx> wrote:
> 
> Hi everyone,
> 
> I've seen several examples of passing arrays by reference such as the
> following:
> 
> $a = array();
> 
> function foo(&a)

function foo(&$a)

> {
>         for ($i=0; $i < 10; i++)
>         {
>                 $a[$i] = $i;
>         }
> }
> 
> foo($a);
> echo "<PRE>";
> print_r($a);
> echo "</PRE>";
> 
> However, when I try this on my setup, it doesn't work and I get the 
> following error message:
> 
> PHP Parse error:  parse error, unexpected T_STRING, expecting 
> T_VARIABLE in...
> 
> Anyone have any ideas or suggestions?
> 
> Thanks,
> Jim
> 
> --
> PHP Windows Mailing List (http://www.php.net/) To unsubscribe, visit: 
> http://www.php.net/unsub.php
> 

--
DB_DataObject_FormBuilder - The database at your fingertips
http://pear.php.net/package/DB_DataObject_FormBuilder

paperCrane --Justin Patrin--

--
PHP Windows Mailing List (http://www.php.net/) To unsubscribe, visit:
http://www.php.net/unsub.php

-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux