|
Posted by NC on 10/10/54 11:32
luke wrote:
>
> I have an idea like this....
>
> $array = array(red, blue, green );
>
> I want it to rpint out this
>
> 1red
> 2blue
> 3green
>
> but cannot figure out how to do it without going through and
> keying the array, can someone please put me out of my misery?
foreach ($array as $key=>$item) {
echo ($key+1), $item;
}
Note that by default, elements of an array in PHP are numbered starting
from zero, hence, ($key+1) in the echo statement.
Cheers,
NC
Navigation:
[Reply to this message]
|