associative-array

XML vs. Array in Flash

In manipulating data in Flash, which data format gives faster speeds in terms of searching and manipulation, XML or nested associative arrays? Meaning I currently send data in strings into the Flash client (I don't want to load an XML file) but I'm not sure if formatting the data into an XML file or into nested associative arrays is bett...

How do I create and add anonymous hashes to a known Hash during script execution?

I'll attempt to illustrate this with an example. Take a common example of a Hash of Hashes: my %HoH = ( flintstones => { lead => "fred", pal => "barney", }, jetsons => { lead => "george", wife => "jane", "his boy" => "elroy", }, simpsons => { lead => "homer",...

Finding last pair in associative array

I'm looping through an associative array with a foreach. I'd like to be able to check if the key value pair being handled is the last so I can give it special treatment. Any ideas how I can do this the best way? foreach ($kvarr as $key => $value){ // I'd like to be able to check here if this key value pair is the last // so I can...

Using associative array values from within the same array

I'm trying to access an associative array's key and value from within the same array. If I have 3 pairs in my array. Can I use the value of let's say the values of something and other within the third one another? $gar = array("something" => "something value", "other" => "other value", "another" => something...

How to use an Oracle Associative Array in a SQL query

ODP.Net exposes the ability to pass Associative Arrays as params into an Oracle stored procedure from C#. Its a nice feature unless you are trying to use the data contained within that associative array in a sql query. The reason for this is that it requires a context switch - SQL statements require SQL types and an associative array p...

Flex Associative Array

User inputs a comma separated string and i d like to make a an associative array out of it as follows : Input : 4,3,3,2,2 Output : Array{"0"=>4,"1"="3","2"=>3,"3"=>2,"4"=>2} I can create an array by input.text.split(","); But I d like to make it an associative array as above, how to do this? Thanks. ...

How to write a good PHP database insert using an associative array

In PHP, I want to insert into a database using data contained in a associative array of field/value pairs. Example: $_fields = array('field1'=>'value1','field2'=>'value2','field3'=>'value3'); The resulting SQL insert should look as follows: INSERT INTO table (field1,field2,field3) VALUES ('value1','value2','value3'); I have come u...

What is the appropriate data structure for this array in CSharp?

Hey guys, If I've got this data structure in PHP, what data structure is the best for it in C#? $array = Array( [dummy1] => Array ( [0] => "dffas", [1] => "asdas2", [2] => "asdasda" ), [dummy2] => Array ( [0] => "asdasd", [1] => "sdfsdfs",...

assigning to an associative array slice in php

In perl, I could assign a list to multiple values in a hash, like so: # define the hash... my %hash = ( foo => 1, bar => 2, baz => 3, ); # change foo, bar, and baz to 4, 5, and 6 respectively @hash{ 'foo', 'bar', 'baz' } = ( 4, 5, 6 ); Is there any way to do the same in php? In fact, is there even a way to get a slice of an ass...

Origin of "map" in Computer Science

In computer science, there are two definitions of the word map. The first is as an associative array, a type of container that maps values of one type to values of another type. An example of this is the STL map. The second definition is from functional programming, in which map applies is a function that takes a list and a function, app...

Flex Dictionary Sorting

I have the following dictionary in flex, and i d like to sort it by value. Couldn't find any resource. '1'=>2, '0' =>1, '3'=>4 .. Any ideas ? How can i sort this by value ? ...

Annoyances of Flex - Associative Array

I have an associative array and while iterating through this array, using foreach loop. Flex is loosing the order. This is so annoying. Why is this happening? How can i avoid this? ...

Constant-time hash for strings?

Another question on SO brought up the facilities in some languages to hash strings to give them a fast lookup in a table. Two examples of this are dictionary<> in .NET and the {} storage structure in Python. Other languages certainly support such a mechanism. C++ has its map, LISP has an equivalent, as do most other modern languages. It...

ActionScript 2: How do I determine the number of keys in an associative array without iterating?

Is there a function that allows me to determine the number of keys in an ActionScript 2 associative array without iterating over that array? // ascertain the length/size of an associative array var o:Object = new Object(); o["k1"] = "v1"; o["k2"] = "v2"; o["k3"] = "v3"; I'd expect there to be an "o.size" or "o.length" that would retur...

JAVA myString['name'] = "my value"; (like in Php)

In Php I really often use this one: $conn_sets = array(); $conn_sets['login'] = "aaa"; $conn_sets['pass'] = "bbb"; How to do the same in JAVA 1.6. I tried to do this: private method1() { String[] mystring = new String[] {"login" => "aaa", "pass" => "bbb"}; } But it give's me an error. I want to make this work, because I hav...

PHP - How to loop through a associative array and get the key name?

My associative array: $arr = array( 1 => "Value1" 2 => "Value2" 10 => "Value10" ); Using the following code, $v is filled with $arr's values foreach($arr as $v){ echo($v); // Value1, Value2, Value10 } How do I get $arr's keys instead? foreach(.....){ echo($k); // 1, 2, 10 } ...

Associative array with multiple keys types, possible?

Ive got a large bunch of objects (potentially 1000's) which I need to store in a container. I need to be able to find specific instances in two ways, either by its ID number (64bit unsigned int), or its name (std::string). Generally by ID will be the most common, however in some cases the name is known, but not the ID. std::map can prov...

How to remove values from an array whilst renumbering numeric keys

I have an array which may contain numeric or associative keys, or both: $x = array('a', 'b', 'c', 'foo' => 'bar', 'd', 'e'); print_r($x); /*( [0] => a [1] => b [2] => c [foo] => bar [3] => d [4] => e )*/ I want to be able to remove an item from the array, renumbering the non-associative keys to keep them sequen...

PHP: Get n-th item of an associative array

If you have an associative array: Array ( [uid] => Marvelous [status] => 1 [set_later] => Array ( [0] => 1 [1] => 0 ) [op] => Submit [submit] => Submit ) And you want to access the 2nd item, how would you do it? $arr[1] doesn't seem to be working: foreach ($form_state['valu...

Javascript: Using integer as key in associative array?

When I create a new javascript array, and use an integer as a key, each element of that array up to the integer is created as undefined. for example: var test = new Array(); test[2300] = 'Some string'; console.log(test); will output 2298 undefined's and one 'Some string'. How should I get javascript to use 2300 as a string instead of...