Results 1 to 2 of 2
  1. #1

    Question Problem of function each() ,pls tell me why.thx.

    Problem of function each() ,pls help me.

    PHP(version 4.0.4pl1) CODE AS FOLLOWING:
    #---------------------------------------------------------

    //declare an array outside functions
    $Columns = array(
    "youth_kind.cid"=>"CateID"
    ,"youth_kind.display"=>"Name"
    ,"youth_kind.ctype"=>"Type"
    ,"youth_kind.showorder"=>"Order"
    ,"youth_kind.cr_time"=>"Create"
    );

    //declare 3 funcitons
    function TravArray1(){
    global $Columns;
    echo "count(Columns)=".count($Columns)."<br>";
    while(list($val,$nam)=each($Columns)){
    echo "$val=>$nam<br>";
    }
    }

    function TravArray2(&$Columns){
    echo "count(Columns)=".count($Columns)."<br>";
    while(list($val,$nam)=each($Columns)){
    echo "$val=>$nam<br>";
    }
    }

    function TravArray3(){
    global $Columns;

    $keys = array_keys($Columns);
    for($i=0;$i<count($keys);$i++){
    echo $keys[$i]."=>".$Columns[$keys[$i]] ;
    }
    }

    //exec 3 functions
    TravArray1();
    TravArray2($Columns); //param by ref
    TravArray3();


    #---------------------------------------------------------


    prolem found.
    function TravArray1() and TravArray2() , no word output.
    the function "each()" can not get data from array $Columns?

    at last i had to do as function "TravArray3()" to travers the
    array.


    is it a bug of PHP, or that's something i do not understand.


    sb. help me pls.

    give a reason pls.
    Last edited by [D.K]; 10-16-2002 at 03:26 AM.
    Life's Base on your heart.

  2. #2
    Oh,no.

    i got it.

    thank you for reading this post.

    the point is function list().





    BTW:i cannot delete my post.
    Life's Base on your heart.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •