|
|
||||||
|
#1
|
|
|
|
|
myarray=array()
myarray['a']=1 myarray['b']=1 myarray['c']=1 Is there an iterative way to find out the array index values ('a', 'b' and 'c') of myarray? |
|
|
|
#2
|
|
|
|
|
foreach ($myarray as $key => $value)
{ echo "$key = $value"; } [..] |
|
#3
|
|
|
|
|
Jake McHenry wrote:
> foreach ($myarray as $key => $value) > { > echo "$key = $value"; > } Thanks. I just found that there is an array_key() function. |
|
#4
|
|
|
|
|
itoctopus wrote:
> Note, however, that array_keys is not recursive. foreach is recursive??? thanks. |
|
#5
|
|
|
|
|
Note, however, that array_keys is not recursive.
|
|
#6
|
|
|
|
|
> -----Original Message-----
> From: news [mailto:news] On Behalf Of Man-wai Chang > Sent: Sunday, April 01, 2007 2:45 PM > To: php-general > Subject: [PHP] Re: finding the index name of an associative array > > itoctopus wrote: > > Note, however, that array_keys is not recursive. > > foreach is recursive??? thanks. > > -- [Peter Lauri - DWS Asia] foreach is NOT recursive :) |
|
#7
|
|
|
|
|
foreach is also not recursive, writing a recursive function to recursively
return the keys in an array should be trivial. |
|
#8
|
|
|
|
|
Man-wai Chang wrote:
> myarray=array() > myarray['a']=1 > myarray['b']=1 > myarray['c']=1 > > Is there an iterative way to find out the array index values ('a', 'b' > and 'c') of myarray? > array *array_keys* ( array $input [, mixed $search_value [, bool $strict]] ) *array_keys()* returns the keys, numeric and string, from the /input/ array. http://www.php.net/manual/en/function.array-keys.php |
|
|
| Similar Threads | |
| associative array of associative arrays Hi, I'm returning an associate array of associative arrays from my powershell script to my C# code using RunspaceInvoke.Invoke(). I get back a single PSObject whose... |
|
| finding an array index The routines below work fine, but is there a more elegant way to do the second one? It seems there would at least be a built-in function to return the ordinal position of an... |
|
| Regular Expression Result as Associative Array Index Hi Everyone. $layout=ereg_replace("\[\[([a-z:0-9]+)\]\]", $dillo['\\1'], $layout); I'm trying to use the result of a Regular Expression Match as an Index for the... |
|
| How to query the index value of associative array Hello PowerShellers, How do I return the index value of an associative array? I'm referencing "Pro Windows PowerShell" by Hristo Deshev, p. 18-24 Problem 1: Array and... |
|
| Data structure for fast associative array with lookup by both key and index Hi all, I'm looking for a data structure for an associative array with the following properties: - Maintains key/value pairs. - Remembers the sequence order in which the... |
|
|
All times are GMT. The time now is 04:50 AM. | Privacy Policy
|