Passing arrays to functions

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Eric Kincl

    Passing arrays to functions

    OK, another quickie,
    How do I pass an array to a function? This is what I have, and the second
    function doesn't seem to be getting the array somehow. I'm sure it's in
    the function declaration...

    function one(){
    return $array; // yes, there is more to this function, and assume that
    "$array" is a real array
    }

    funtcion two($arrayArg){ // <- I'm sure the prob is here.
    print_r($arrayA rg); // This isn't printing anything, when it does in one()
    }

    then I call:
    two(one());


    Once again, I'm sure the prob is in the declaration.

    Thanks in advance,


    -Eric Kincl
  • Justin Koivisto

    #2
    Re: Passing arrays to functions

    Eric Kincl wrote:[color=blue]
    > OK, another quickie,
    > How do I pass an array to a function? This is what I have, and the second
    > function doesn't seem to be getting the array somehow. I'm sure it's in
    > the function declaration...
    >
    > function one(){
    > return $array; // yes, there is more to this function, and assume that
    > "$array" is a real array
    > }
    >
    > funtcion two($arrayArg){ // <- I'm sure the prob is here.
    > print_r($arrayA rg); // This isn't printing anything, when it does in one()
    > }
    >
    > then I call:
    > two(one());
    >
    >
    > Once again, I'm sure the prob is in the declaration.[/color]

    I don't think that the declaration is the problem... For instance, try
    this code:

    <?php
    function one(){ return array(1=>'one', 2=>'two',5,'me too!'); }
    function two($ar){ print_r($ar); };

    $myVar=one();
    two($myVar);

    two(one());
    ?>

    Results:
    Array
    (
    [1] => one
    [2] => two
    [3] => 5
    [4] => me too!
    )
    Array
    (
    [1] => one
    [2] => two
    [3] => 5
    [4] => me too!
    )

    --
    Justin Koivisto - spam@koivi.com
    PHP POSTERS: Please use comp.lang.php for PHP related questions,
    alt.php* groups are not recommended.

    Comment

    Working...