function not returning values into my array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Amzul
    New Member
    • Oct 2007
    • 130

    function not returning values into my array

    hello all,

    i made a function that supposed to feed dual array

    my problam is that the varibal is visibale inside the function but when it return it dies with it. :(

    thats what i want the function to return
    [CODE=php]function sort($n,$mytime stemp,$mytoatl) {
    $ts[$n][0]=$mytimestemp;
    $total[$n][0]=$mytotal;
    return;
    }[/CODE]
    then when i want to use the data i get notice that its empty
    [CODE=php]print_r($ts);
    print_r($total) ;[/CODE]
    i know the first time i use $ts and $total is inside the function
    but even if i first put them at the top of the code or right affter the functin or righr before the function still they dont get updated with $mytimestemp and $mytotal.

    i try to declare it like that :
    A:
    [CODE=php]$ts;
    $total;[/CODE]B:
    [CODE=php]$ts = array();
    $total = array();[/CODE]C:
    [CODE=php]global $ts;
    global $total;[/CODE]
    is it because its array in array?
  • nomad
    Recognized Expert Contributor
    • Mar 2007
    • 664

    #2
    Originally posted by Amzul
    hello all,

    i made a function that supposed to feed dual array

    my problam is that the varibal is visibale inside the function but when it return it dies with it. :(

    thats what i want the function to return
    [CODE=php]function sort($n,$mytime stemp,$mytoatl) {
    $ts[$n][0]=$mytimestemp;
    $total[$n][0]=$mytotal;
    return;
    }[/CODE]
    then when i want to use the data i get notice that its empty
    [CODE=php]print_r($ts);
    print_r($total) ;[/CODE]
    i know the first time i use $ts and $total is inside the function
    but even if i first put them at the top of the code or right affter the functin or righr before the function still they dont get updated with $mytimestemp and $mytotal.

    i try to declare it like that :
    A:
    [CODE=php]$ts;
    $total;[/CODE]B:
    [CODE=php]$ts = array();
    $total = array();[/CODE]C:
    [CODE=php]global $ts;
    global $total;[/CODE]
    is it because its array in array?
    What are you trying to return. Possible a $ value
    your print proved that.

    Comment

    • Amzul
      New Member
      • Oct 2007
      • 130

      #3
      silly me i got it now, affter looking around i notice that
      when calling to a functiuon i need to send it the refrence of the array

      so it should be like that :

      [CODE=php]function sort($n,$mytime stemp,$mytoatl, $ts,$total){
      $ts[$n][0]=$mytimestemp;
      $total[$n][0]=$mytotal;
      return;
      }[/CODE]

      and the call is:
      [CODE=php]sort($n,'2008-01-24','200',&$ts, &$total);[/CODE]

      Comment

      Working...