Re: array problem




julian_m писал(а):

let's say that I've an array like this:

$AL_array = Array (
[0] => Array ( [23] => 1 ) ,
[1] => Array ( [24] => 2 ) ,
[2] => Array ( [25] => 3 ) ,
[3] => Array ( [35] => 4 ) ,
[4] => Array ( [23] => 1 ) ,
[5] => Array ( [31] => 2 ) ,
[6] => Array ( [32] => 1 ) ,
);

and I want to output

key 23 => level 1
key 24 => level 2
key 25 => level 3
key 35 => level 4
key 23 => level 1
key 31=> level 2
key 32=> level 1


I've tried "list" without luck, and I cant see where could be the
problem....


for ($i = 1; $i <= count($AL_array); $i++){

list($id, $level) = $AL_array[$i];
echo "key $id => level: $level<br>";
}

above code prints

key => level
key => level
key => level
key => level
key => level
key => level
key => level

(without the array values)

Any hint?

regards - jm



Try please this:
/////////////////////////////////////////////////////////////////////////
while(list($id, $level) = each($AL_array))
{
list($id1, $level1) = each($level);
echo "key $id1 => level: ".$level1."<br>";
}
/////////////////////////////////////////////////////////////////////////

.



Relevant Pages

  • Re: Zero terminated strings
    ... Or did that famous Standard mung that equivalence too? ... Hint 2: lvalue. ... believe it would stack a pointer to the array. ...
    (comp.lang.c)
  • Re: find a number
    ... requires extending the array to a zeroth element, ... The hint was merely a hint, not a complete specification of the ... iteration you incorrectly subtract 1001 from the sum. ...
    (comp.programming)
  • Re: merge 2 or more files together without creating new file
    ... If you give me some hint or help, ... I am so beginner, almost 4 moths, and not getting anywhere with perl. ... I might be add more logs file into this array later. ... perldoc Email::Send ...
    (perl.beginners)
  • Re: find a number
    ... array, except for one number, which occurs twice. ... Hint: what's the sign ... You have a "fencepost error" in your loop; in the final iteration you incorrectly subtract 1001 from the sum. ... Avoids that means avoids altering the input values. ...
    (comp.programming)
  • Re: merge 2 or more files together without creating new file
    ... If you give me some hint or help, ... I know how to read one file into array. ... I might be add more logs file into this array later. ... perldoc Mail::Send ...
    (perl.beginners)