Reply to Re: array problem

Your name:

Reply:


Posted by David Haynes on 03/31/06 14:29

julian_m wrote:
> 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
>
<?php
$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 )
);

foreach( $AL_array as $al ) {
foreach( $al as $key => $level ) {
printf("key %d => level %d\n", $key, $level);
}
}
?>

-david-

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация