about return a array

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

    about return a array

    When I write this codes:

    <?
    function r_array(&$array ){
    for($i=1;$i<5;$ i++) {
    for($j=1;$j<5;$ j++) {
    $array[i][j] = "d";
    }

    }
    }

    r_array($array2 );
    print_r($array2 );
    echo $array[1][1];
    ?>

    it display in the brower like this:

    Array ( [i] =Array ( [j] =d ) )

    And this means $array[1][1] can't be used. And what's the problem?

    I want return a 2D array and use it like $array[1][1],what should I
    do?

    Regards!

  • Steve

    #2
    Re: about return a array


    "cocobear" <cocobearc@gmai l.comwrote in message
    news:1177425404 .867402.321610@ c18g2000prb.goo glegroups.com.. .
    | When I write this codes:
    |
    | <?
    | function r_array(&$array ){
    | for($i=1;$i<5;$ i++) {
    | for($j=1;$j<5;$ j++) {
    | $array[i][j] = "d";
    | }
    |
    | }
    | }
    |
    | r_array($array2 );
    | print_r($array2 );
    | echo $array[1][1];
    | ?>
    |
    | it display in the brower like this:
    |
    | Array ( [i] =Array ( [j] =d ) )
    |
    | And this means $array[1][1] can't be used. And what's the problem?
    |
    | I want return a 2D array and use it like $array[1][1],what should I
    | do?

    ummmm...put a $ in fron of i and j.

    :)


    Comment

    • dave

      #3
      Re: about return a array

      On Apr 24, 6:36 am, cocobear <cocobe...@gmai l.comwrote:
      When I write this codes:
      >
      <?
      function r_array(&$array ){
      for($i=1;$i<5;$ i++) {
      for($j=1;$j<5;$ j++) {
      $array[i][j] = "d";
      }
      >
      }
      >
      }
      >
      r_array($array2 );
      print_r($array2 );
      echo $array[1][1];
      ?>
      >
      it display in the brower like this:
      >
      Array ( [i] =Array ( [j] =d ) )
      >
      And this means $array[1][1] can't be used. And what's the problem?
      >
      I want return a 2D array and use it like $array[1][1],what should I
      do?
      >
      Regards!
      change $array[i][j] = "d";
      to $array[$i][$j] = "d";


      Comment

      Working...