Re: Arrays and Functions
| From: | Chris Hayes | Date: | Mon, 04 Sep 2000 20:52:41 +0000 |
| Subject: | Re: Arrays and Functions | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-16228@lists.php.net to get a copy of this message | ||
>
> Is it possible to increment and array inside of a function and then call the
> array out side of the funciton. While in side the function I am able to echo
> the array and see what I should see out side of the funtion!
>
> Would I need to use global????
1) return an array from the function as described in the manual at
functions.returning-values.html
2) By default, function arguments are passed by value (so that if you change
the value of the argument within the function, it does not get changed
outside of the function). If you wish to allow a function to modify its
arguments, you must pass them by reference.
see functions.html#FUNCTIONS.USER-DEFINED
> <?
> function alpha($a1) {
so either define
function alpha(&$a1)
OR
call with alpha(&0)
> $a = $a1;
> for ($i=$a;$i<10;$i++) {
> $array1[$i] = $array1[$i] + 1;
> }
>
> return;
OR call like $myarray=alpha(0) then return $array1 (? not sure about the
return)
> };
> for ($i=0;$i<10;$i++) {
> $array1[$i] = 0;
> };
>
> alpha(0);
> ?>
>
> Hello world!!!
> <?
> for ($i=0;$i<10;$i++) {
> echo "<br>The number is :".$array1[$i];
> }
> ?>
>
>
>
cheers,
Chris
--------------------------------------------------------------------
-- C.Hayes Droevendaal 35 6708 PB Wageningen the Netherlands --
--------------------------------------------------------------------