Re: Echo a value from an arrays position

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Will this also work with an associative array? If this is what he is talking about, I tried it and it does not work....

I put this together though and it works, not sure if it is the *best* way though...

<?php
$colors = array('white'=>'#ffffff','black'=>'#000000','blue'=>'#0000ff');

       $count = 0;
       foreach( $colors as $k => $v) {
               $count++;
               if( $count == 2 )
                       echo "\$colors[$k] => $v.\n";
       }
?>

-Brad

Jay Blanchard wrote:

[snip]
Is there any way to call for an element value in an array by the
position?
Like position 2 in the array and not the key name.
[/snip]

I hate to say this, but you really need to RTFM http://www.php.net/array

To get a value from position 2 in an array you use $arrayName[1] (all
array elements start numbering at 0, unless you do something to the
array to change it).


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux