Um...I think you could just use "global". As in:

global $domain, $tld, $firstname, $lastname, $userid;

Once a variable is declared global, any change to that variable inside the
function is reflected outside of the function.

So:

function before_after ()
{
global $var;

echo $var . "<BR>";

$var = "After";

echo $var . "<BR>";
}

$var = "Before";

echo $var . "<BR>";

before_after();

echo $var . "<BR>";


Hey, it is PHP. It's supposed to be simple ;)

Unless of course I'm wrong in this untested example, in which PHP was
designed to make you suffer agonizing pain and terror that strikes to the
very depth of your soul.

Or not.

Because it does work.

But there is one odd behavior I noticed.

If you change a variable inside a function, then declare it global,
declaring it global reverts it's value to what it was before the function
adjusted it (when global is inside the function, that is).

But if you first declare it global THEN change the value, it works as above.
Kinda neet, I thought.



--
Plutarck
Should be working on something...
...but forgot what it was.


"Lindsay Adams" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> On 4/5/01 3:56 PM, "Matt McClanahan" <[EMAIL PROTECTED]> wrote:
>
> > On Thu, Apr 05, 2001 at 01:40:54PM -0700, Richard Kurth wrote:
> >
> >> Is there another way to write this I would like to make it smaller
> >> also How would I write it so it is a function and I would be able to
use all
> >> the data throughout the  whole program every time I try the rest of the
> >> program does not see the data
> >
> >>  $domain=$data[0];
> >>  $tld=$data[1];
> >>   $firstname=$data[2];
> >>  $lastname=$data[3];
> >>  $userid=$data[4];
> >>  $passw=$data[5];                this part  would like to make smaller
> >>   $email=$data[6];
> >>  $package=$data[7];
> >>  $frontpage=$data[8];
> >>  $mysql=$data[9];
> >>  $userdatabase=$data[10];
> >>  $newuser =$data[11];
> >> $newuserpass =$data[12];
> >
> > Use list()
> >
> > list($domain,$tld,$firstname,$lastname,$userid,.....) = $data;
> >
> > If you want to put it in a function, declare them all globals
beforehand.
> >
> > function myfunc()
> > {
> >  global $domain,$tld,$firstname,$lastname,$userid...;
> >
> > Matt
>
> Umm, you can add them to the global space this way.
> Inside a function.
>
> $GLOBALS['domain']=data[0];
> $GLOBLAS['tld']=data[1];
> ...
>
>
> Can't you? Everyone?
>
> Or you can pass as a reference in the last parameter of your function
call,
> the variable that you want returned as an array
>
> Function get_data($parm,$parm,&$array_parm)
>
> And set the values of $array_parm['variablename']=whatever
> Inside the function, and return $array_parm at the end of the function
call.
>
> So, if you called your function as
>
> get_data("somethinghere","somethingelse",$returned_array);
>
> $returned_array['domain'] will equal whatever $data[0] was
>
> But I think adding the variable to the GLOBAL array will work fine.
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to