Associative array key order
H. S. Teoh
hsteoh at quickfur.ath.cx
Wed Jul 31 07:54:57 PDT 2013
On Wed, Jul 31, 2013 at 04:41:14PM +0200, Daniel Kozak wrote:
>
> D:
>
> foreach(key, val; ["query" : 1, "count" : 2]) writeln(key); // print
> count query
> foreach(key, val; ["count" : 1, "query" : 2]) writeln(key); // print
> count query too
>
> PHP:
> foreach(["query" => 1,"count"=>2] as $key => $val)
> echo $key; // print query count
> foreach(["count" => 1,"query"=>2] as $key => $val) echo $key;
>
>
> is there a way for AA to change order?
AA's in D are unordered. If you want a specific order, you should use an
array, or sort the AA keys before looping over them.
T
--
I see that you JS got Bach.
More information about the Digitalmars-d-learn
mailing list