associative-array

Nested foreach loops for associative array combinations

I have an associative array as follows: $myarray = array('a'=>array(), 'b'=>array(), 'c'=>array(), 'd'=>array()); I want to be able to get all pairs of elements in the array. If it wasn't an associative array, I would use nested for loops, like: for($i=0; $i<count($myarray); $i++) { for($j=$i+1; $j<count($myarray); $j++) { do_s...

Return an Oracle Associative Array from a function

Does anybody know if it is possible to return an associative array as the result of an Oracle function, if so do you have any examples? I have an Oracle package which contains an associative array declaration as defined below: TYPE EVENTPARAM IS TABLE OF NUMBER INDEX BY BINARY_INTEGER; This is then used in a stored procedure ...

Passing an array of structures to an Oracle stored procedure (CFMX)

I'm looking to write a Oracle stored procedure where I would pass in (from ColdFusion) an array of structures and loop over each iteration to insert the bits and pieces within the structures to the DB., I haven't written this type of procedure / package before. I am planning to do an sp / package similar to what is sketched out in the...

How to make a object (class) foreachable in D?

Hi, how can I make a class usable in a foreach statement? The class contains a associative array (e.g. string[string]). So the foreach statement use this array as source. So this is what I want: auto obj = new Obj(); foreach (key, value; obj) { ... } Do I need to implement a interface someting like that? EDIT: The solution: p...

Awk array iteration for multi-dimensional arrays

Awk offers associative indexing for array processing. Elements of 1 dimensional array can be iterated: e.g. for(index in arr1) print "arr1[" index "]=" arr1[index] But how this kind done for a two dimensional array? Does kind of syntax,given below work? for(index1 in arr2) for(index2 in arr2) arr2[index1,index2] ...

JSON to PHP Associative array

Hey guys, would any of you know a good way to put this into an associative array . I have tried json_decode but found it to not be much help and: preg_match_all('|"name": "(.*?)",|',$json,$matches); Seems to match it (in expresso) but returns an empty array in php. This is the data i need to put into an associative array: { ...

JavaScript associative array by variable

I'd like to pass a variable into the key of my monthHash variable here: var monthHash = new Array(); monthHash["JAN"] = "Jan"; monthHash["FEB"] = "Feb"; ... monthHash["NOV"] = "Nov"; monthHash["DEV"] = "Dec"; Such that I can do this: alert(monthHash[the_variable]); Instead of using a switch case to go through this. When...

How to iterate over assoziative array in bash

Based on an assoziative array in a bash script I need to iterate over it to get key & value. #!/bin/bash declare -A array array[foo]=bar array[bar]=foo I actually don't understand how to get the key while using a for-in loop. Thanks in advance! ...

Associative array with mixed (numerical and string) indices?

How would one implement a dynamic associative array that could take any number of mixed indices (integers, strings, or both)? I aim to simulate structures by providing, for example, people[3].location as syntactical sugar for people[3, "location"]. How would you recommend representing this kind of array internally? By the way, I am usi...

Hash tables VS associative arrays [PHP]

Recently I have read about hash-tables in a very famous book "Introduction to Algorithms". I haven't used them in any real applications yet, but wanted to. But don't know how to start. Can anyone give me some samples of using it, for example, how to realize dictionary application (like ABBYY Lingvo) using hash-tables? And finally wanted...

accessing assocative array item by index

I want to access information in an associative array by index like so $arr = Array( ['mgm19'] => Array( ['override'] => 1 ) ); $override1 = $arr['mgm19']['override']; $override2 = $arr[0]['override']; but i get nothing from override2 why ? ...

Is it bad to have a long name for an associative array in PHP?

I have a function which must return one dimensional associate array, like $user_info[$index]=value where $index is a string which consist of user_id full_name photo_file_name for example, my associative array could look like $user_info['user-123456789~~Bill Gates~~bill_gates.png']=$value. I need user_id, full_name and photo for anot...

Associative Array where a class TypeInfo is key in D?

I'd like to be able to create an multidim associative array where one dimension is a class. Like this: class Node{ Node[?classType?][string] inputs; } so that I later can do Node[] getInputsOfType(?? aClass){ if(aClass in this.inputs) return this.inputs[aClass]; else return null; } // meanwhile in another file....

add arrays to associative aaray in php

<?php $tab=1;/*$_GET['tab'];*/ $id=1111;/*$_GET['id'];*/ include_once('solve.php'); $query="SELECT user_job.level1, user_job.tab_level, job.money_gain, job.exp_gain, job.energy_required, job.name,job.job_id FROM user_job RIGHT JOIN job USING(job_id) WHERE job.tab=".$tab." AND user_job.user_id=".$id." LIMIT 0,10"; $resu...

Associative arrays in javascript to JSON

I am using array as an associative array of objects in which keys are ID number of objects in database. Quiet naturally- IDs are large numbers - so that means it is common to have array of length 10^4 with only 20 elements as valid real objects. I want to send this data back to server but whatever plugins I had to convert js objects to...

Java:Internal data structure in Map

I am trying to create a class that implements the Map interface. So I am writing code that will check if the calling object is empty or not. However I am a little confused as to which data structure I should use internally. At present I am using a Hash Table. Thanks in advance ...

Creating associative arrays in JavaScript

Using the following code: $credits.getCredits = function() { return $(this).find( 'tbody' ).children( 'tr' ).map(function(){ var $name = $(this).children(':first').html(); var $role = $(this).children(':nth-child(2)').html(); return { $role: $name }; }).get(); } Which looks through the elements of a cr...

Ruby on Rails - Which method should I override for Album.first.photos?

I've overrode the method find for ActiveRecord::Base and that went pretty well, now I can customize it nicely. def self.find(*args) # my custom actions super(*args) end then Album.find(1) #=> My custom result But now I would like to override this: Album.first.photos and I'm not sure what method exactly I should override to ...

Multiple foreach without nesting

This first block of code works as expected. It's a foreach to print values from an $fnames key-value array. foreach($fnames as $fname){ echo $fname; } The $fnames array has an $lnames array that correspond to it, and I'd like to print the lname with the fname at the same time, something like this: but it doesn't compile foreach($f...

passing array parameters to smarty PHP template include

On a PHP site using the smarty template engine (or at least a close relative of smarty), I am calling a template include file ("header.html") which contains this code excerpt, along with other HTML omitted here for clarity: <title>{$title|escape:"html"}</title> {if isset($META) && $META} {foreach from=$META item=m} <meta nam...