associative-array

Iterating over a complex Associative Array in PHP

Is there an easy way to iterate over an associative array of this structure in PHP: The array $searches has a numbered index, with between 4 and 5 associative parts. So I not only need to iterate over $searches[0] through $searches[n], but also $searches[0]["part0"] through $searches[n]["partn"]. The hard part is that different indexes ...

How to pass an array parameter in TOAD

Using toad and an oracle database, how can I call a sp and see the results by passing an array to one of the parameters of the sp? ...

In PHP, how do I find the value associated with a specific key.

I have two arrays. One contains id=>count and the other contains id=>name. I'm trying to produce a single array that is name=>count. Any suggestions on a straightforward way to do this? I have looked at the Array Functions in the PHP Manual and didn't see anything that stood out as doing what I want, so I'm guessing I'll need a combinat...

Javascript fake dictionarys

I've declared Javascript arrays in such a way that I could then access them by a key, but it was a long time ago, and I've forgotten how I did it. Basically, I have two fields I want to store, a unique key, and its value. I know there is a way to do it.. something like: var jsArray = new {key: 'test test', value: 'value value'}, ...

In PHP, how do you change the key of an array element?

I have an associative array in the form key => value where key is a numerical value, however it is not a sequential numerical value. The key is actually an ID number and the value is a count. This is fine for most instances, however I want a function that gets the human-readable name of the array and uses that for the key, without changi...

How do you remove a value that has an empty key from an associative array in PHP?

I have a key that appears to be an empty string, however using unset($array[""]); does not remove the key/value pair. I don't see another function that does what I want, so I'm guessing it's more complicated that just calling a function. The line for the element on a print_r is [] => 1, which indicates to me that the key is the empty st...

Is there a way to find how how "deep" a PHP array is?

A PHP array can have arrays for its elements. And those arrays can have arrays and so on and so forth. Is there a way to find out the maximum nesting that exists in a PHP array? An example would be a function that returns 1 if the initial array does not have arrays as elements, 2 if at least one element is an array, and so on. ...

Is it good practice to initialize the elements in an associative array in php?

I'm finding myself doing a lot of things with associative arrays in PHP. I was doing this: foreach ($item as $key=>$value) { if ($arr[$key] == null) { $arr[$key] = 0; } $arr[$key] += $other_arr[$value]; } But then I realised that it works fine if I exclude the line that initializes $arr[$key], presumably since it...

How do I remove objects from a javascript associative array>

var myArray = new Object(); myArray["firstname"] = "Bob"; myArray["lastname"] = "Smith"; myArray["age"] = 25; Now if I wanted to remove "lastname"?....is there some equivalent of myArray["lastname"].remove()? (I need the element gone because the number of elements is important and I want to keep things clean). Thanks in advance to eve...

Dynamically creating keys in javascript associative array.

Simple, quick, question. How can I create dynamically create keys in javascript associative arrays? All the doc I've found so far is to update keys that are already created: arr['key'] = val; I have a string like this " name = oscar " And I want to endup with something like this: { name: 'whatever' } That is I split the string...

How are javascript arrays implemented?

Namely, how does the following code: var sup = new Array(5); sup[0] = 'z3ero'; sup[1] = 'o3ne'; sup[4] = 'f3our'; document.write(sup.length + "<br />"); output '5' for the length, when all you've done is set various elements? EDIT: Forget the comparison to using it like a hashmap. I think this was confusing the issue. My 'problem' ...

javascript - associative array without toString, etc...

I want to create an associative array: var aa = {} //equivalent to Object(), new Object(), etc... and I want to be sure that any key I access is going to be a number: aa['hey'] = 4.3; aa['btar'] = 43.1; I know JS doesn't have typing, so I can't automatically check this, but I can ensure in my own code that I only assign strings to ...

Fastest way to implode an associative array with keys

I'm looking for a fast way to turn an associative array in to a string. Typical structure would be like a URL query string but with customizable separators so I can use '&amp;' for xhtml links or '&' otherwise. My first inclination is to use foreach but since my method could be called many times in one request I fear it might be too slo...

PHP Arrays, appending depth of array item recursively to an array with the key of 'depth'

Per the example array at the very bottom, i want to be able to append the depth of each embedded array inside of the array. for example: array ( 53 => array ( 'title' => 'Home', 'path' => '', 'type' => '118', 'pid' => 52, 'hasChildren' => 0, ), Has a depth of one accordin...

Creating package-level associative array in java

Is it possible to create a java representation of a package-level oracle associative array. For example, given the following: CREATE OR REPLACE PACKAGE MyPackage AS TYPE t_numbers IS TABLE OF NUMBER INDEX BY PLS_INTEGER; I find I cannot write the following java: ArrayDescriptor descriptor = ArrayDescriptor.createDescriptor("M...

PHP Arrays, appending count of array items recursively to an array

Pointless Dribble Okay This is another weird one from me, i want to thank OIS for helping me out on my last question... which deals with this same kind of funky array manipulation... i studied that code in depth and i feel it has helped me become better with recursive array manipulative functions. However, once again i find my self in ...

Concise Method for Passing Associative Arrays to Method

Looking for a way to pass an associative array to a method. I'm looking to rewrite an Actionscript tween package in C# but running into trouble with "associative" arrays/objects. Normally in Actionscript I might do something like: public function tween(obj:DisplayObject, params:Object = null):void { if (params.ease != null) { ...

Extracting a subset of values from an associative array (php)

I want to do something seemingly very simple, but I can't find anything about it: simply extract a subset of an array similar to array_splice, but using keys to retrieve the values : $data = array('personName' => 'John', 'personAge' => 99, 'personId' => 1, /* many more data I don't need here ... */); list($name, $age, $...

How to sort a date array in PHP

I have an array in this format: Array ( [0] => Array ( [28th February, 2009] => 'bla' ) [1] => Array ( [19th March, 2009] => 'bla' ) [2] => Array ( [5th April, 2009] => 'bla' ) [3] => Array ( [19th April, 2009] => '...

Passing an associative array from c# to Powershell

I'd like to pass an associative array from C# to Powershell. As an example I'd like to execute this powershell line of code: PS C:\> get-command | select name, @{N="Foo";E={"Bar"}} -first 3 Name Foo ---- --- Add-Content ...