Returning a 2 dimensional array

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

    #16
    Re: Returning a 2 dimensional array

    On Thu, 03 Nov 2005 14:48:19 -0500, JDS wrote:
    [color=blue]
    > As simple as this:
    >
    > function get_2d_array(){
    > return array(array());
    > }
    > }[/color]

    oops! Looks like I got an extra close-curly brace in there. typo, you know.

    --
    JDS | jeffrey@example .invalid
    | http://www.newtnotes.com
    DJMBS | http://newtnotes.com/doctor-jeff-master-brainsurgeon/

    Comment

    • Parrot

      #17
      Re: Returning a 2 dimensional array

      On 4 Nov 2005 06:18:00 -0800, "Chung Leong"
      <chernyshevsky@ hotmail.com> wrote:
      [color=blue]
      >That's the result from the following:
      >
      >1: function test()
      >2:{
      >3: $array[0][0] = "Hello";
      >4: $array[0][1] = "World";
      >5: $array[1][0] = "How Are";
      >6: $array[1][1] = "You?";
      >7: return array($array);
      >8:}
      >
      >The function I gave you was:
      >
      >1: function test()
      >2:{
      >3: $array[0][0] = "Hello";
      >4: $array[0][1] = "World";
      >5: $array[1][0] = "How Are";
      >6: $array[1][1] = "You?";
      >7: return $array;
      >8:}
      >
      >Note the difference at line 7.[/color]

      Ah yes, I forgot that I added that... I was trying to follow JDS'
      advice.

      Okay, that works... but now that leaves the question of why didn't my
      original code work?

      Comment

      • JDS

        #18
        Re: Returning a 2 dimensional array

        On Fri, 04 Nov 2005 11:31:43 -0500, Parrot wrote:
        [color=blue]
        > Okay, that works... but now that leaves the question of why didn't my
        > original code work?[/color]

        because something was wrong with it.

        ha! ha ha ! funny

        no, but seriously, something must've been wrong.

        --
        JDS | jeffrey@example .invalid
        | http://www.newtnotes.com
        DJMBS | http://newtnotes.com/doctor-jeff-master-brainsurgeon/

        Comment

        • Sergej Andrejev

          #19
          Re: Returning a 2 dimensional array

          Parrot wrote:[color=blue]
          > I am trying to program a function to return a 2 dimensional array, but
          > it's not working. I reduced the return value to 1 dimension and
          > tested that to make sure that the problem wasn't elsewhere. It had no
          > problem when the array was 1 dimensional.
          >
          > Is there something different I need to do in order to return a 2
          > dimensional array from a function?[/color]

          Are you shore you don't want to pass array by reference like this:

          <?
          function r_array(&$array ){
          $array[0][0] = "a";
          $array[0][1] = "b";
          $array[1][0] = "c";
          $array[1][1] = "d";
          }

          r_array($array2 );
          print_r($array2 );
          ?>

          Comment

          • Parrot

            #20
            Re: Returning a 2 dimensional array

            On Fri, 04 Nov 2005 14:30:50 -0500, JDS <jeffrey@exampl e.invalid>
            wrote:
            [color=blue]
            >On Fri, 04 Nov 2005 11:31:43 -0500, Parrot wrote:
            >[color=green]
            >> Okay, that works... but now that leaves the question of why didn't my
            >> original code work?[/color]
            >
            >because something was wrong with it.
            >
            >ha! ha ha ! funny
            >
            >no, but seriously, something must've been wrong.[/color]

            Thanks for the insight.

            Comment

            • JDS

              #21
              Re: Returning a 2 dimensional array

              On Fri, 04 Nov 2005 22:25:32 -0500, Parrot wrote:
              [color=blue]
              > Thanks for the insight.[/color]

              You're welcome.

              --
              JDS | jeffrey@go.away .com
              | http://www.newtnotes.com
              DJMBS | http://newtnotes.com/doctor-jeff-master-brainsurgeon/

              Comment

              Working...