associative-array

How to create a 2D map in Java?

I would like to have a mapping which maps two string into one string. For example: map["MainServer","Status"] return "active". What is the best way to do it in Java. Should I use HashMap which include another HashMap as its elements? ...

Mapping multiple keys to the same value in a Javascript hash

I use a Javascript hash object to store a set of numerical counters, set up like this [this is greatly simplified]: var myHash = { A: 0, B: 0, C: 0 }; Is there a way to make other keys, ones not explicitly in myHash, map to keys that are? For instance, I'd like [again, this is simplified]: myHash['A_prime']++; // or myHas...

Inserting only unique values into an array

I have a set of values that I'm pushing into an array in the order they occur $valsArray = array(); //I process each value from a file (code removed for simplicity) //and then add into the array $valsArray[] = $val; How do I turn this into an associative array instead where the value gets inserted (as $key of associative array)...

Doing a "Diff" on an Associative Array in javascript / jQuery?

If I have two associative arrays, what would be the most efficient way of doing a diff against their values? For example, given: array1 = { foreground: 'red', shape: 'circle', background: 'yellow' }; array2 = { foreground: 'red', shape: 'square', angle: '90', background: 'yellow' }; How would I ch...

Flex TileList with associative array

I have an associative array that I want to display using TileList. However, it doesn't understand what is being fed to it. All I got is [object] in the TileList. [bindable] public var people as array = new array(); private function loadArray():void{ people = decoded JSON array showPeople.dataProvider = people;} <mx:Tilelist id="show...

Build associative array based on values of another associative array

I'm looking for an elegant way to turn this array: Array ( [foo] => 1 [bar] => 1 [zim] => 3 [dib] => 6 [gir] => 1 [gaz] => 3 ) Into this array: Array ( [1] => Array ( foo, bar, gir ), [3] => Array ( zim, gaz ), [6] => Array ( dib ) ) Note:, there is no relationship between the keys or values. They are completely a...

Javascript Associative Arrays

Hello all, It seems to me that this should work but I cant see what exactly is the problem. The error Im receiving is "DDROA is not defined" Could anyone help enlighten me. var DDROA = { AllowedRoutes : { AR0 : {text : 'SomeText', value : 'SomeValue'}, AR1 : {text : 'SomeText2', value : 'SomeValue2'} }, ...

Comment associative array in PHP Documentor

Hey Guys, i hope someone can help me out on this one here. I use several associative arrays in my php application and i'm using php documentor to comment my sources. I never really did specified comments for the arrays in an array, but now i need to do that and dont know how. $array = array('id' => 'test', 'class' => 'tester', 'options'...

PL/SQL bulk collect into associative array with sparse key

I want to execute a SQL query inside PL/SQL and populate the results into an associative array, where one of the columns in the SQL becomes the key in the associative array. For example, say I have a table Person with columns PERSON_ID INTEGER PRIMARY KEY PERSON_NAME VARCHAR2(50) ...and values like: PERSON_ID | PERSON_NAME ...

Variables versus constants versus associative arrays in PHP

I'm working on a small project, and need to implement internationalization support somehow. I am thinking along the lines of using constants to define a lot of symbols for text in one file, which could be included subsequently. However, I'm not sure if using variables is faster, or if I can get away with using associative arrays without ...

Add a element to a PHP associative array.

1=>america,2=>India,3=>england Above is my associative array. How can I bring 3=>england to front of the array? ...

array_splice() - Numerical Offsets of Associative Arrays

I'm trying to do something but I can't find any solution, I'm also having some trouble putting it into works so here is a sample code, maybe it'll be enough to demonstrate what I'm aiming for: $input = array ( 'who' => 'me', 'what' => 'car', 'more' => 'car', 'when' => 'today', ); Now, I want to use array_splice() to re...

printing multi dimentional array

i have this multi dimentional array that i want to print into a table having each record/item go into its own row but it goes column wise. this is the output that im getting: http://mypetshopping.com/product.php ps: the value of $product will by dynamic based on what product is being viewed. <?php session_start(); ?> <table> <thead> <t...

Sum of a row of an associative array using PHP?

Is there a php function that returns the sum of a row of an associative array? If not should I just use a counter and a foreach loop? Appreciate it! ...

Compare two associative arrays and create a new array with the matched arrays, PHP

I have this two arrays: $arr1=array( array("id" => 8, "name" => "test1"), array("id" => 4, "name" => "test2"), array("id" => 3, "name" => "test3") ); $arr2=array( array("id" => 3), array("id" => 4) ); How can i "extract" arrays from $arr1, where id have same val...

php associative array name?

hello! Just trying to get the name of an assoc array; $test = array('selected' =>$selected, 'sectionList'=>$sectionList, 'categoryList'=>$categoryList); <? foreach($test as $list) { ?> <h3><?=$list?>, <?=$list[id]?>, <?=$list['name']?>, <?=$list['value']?></h3> <? } ?> but either get 'Array' or nothing?! I can see the name when i prin...

PHP Associative array sort

I have an array like one below. Currently it is sorted alphabetically by the OwnerNickName field. Now i want to brig the array entry with OwnerNickName 'My House' as the first entry of the array and rest sorted alphabetically by OwnerNickName. Any idea? Array ( [0318B69D-5DEB-11DF-9D7E-0026B9481364] => Array ( [O...

Help with PHP and associative arrays

Hello. I have to do a simple calculator in php based on user's input and choice from select field, something like this: <?php $a = $_GET['a']; $b = $_GET['b']; $array = array( "option1" => 0.1, "option2" => 0.15, "option3" => 0.3, "option4" => 3, "option5" ...

How do I return specific keys from the $_POST array?

I would like to check to see if there are any keys in $_POST that contain a string. The string will not be the full key, only part of the key. (ie. search string = "delRowID", $_POST key = "delRowID_16"). I have tried to use array_keys($_POST,"delRowID"), but it has never returned anything. CODE print_r($_POST); print_r(array_keys($_PO...

jQuery - change a list of elements to an associative array

Given an associative array (of the sort returned by jQuery.serializeArray()) like this: [ { 'name': 'abc', 'value': 'aaa', '__proto__': [Object] }, { 'name': 'def', 'value': 'bbb', '__proto__': [Object] }, { 'name': 'abc', 'value': 'ccc', '__proto__': [Object] } ] How can one convert this, using either jQuery or just javascript, to an...