associative-array

Google Chrome: JavaScript associative arrays, evaluated out of sequence

Ok, so on a web page, I've got a JavaScript object which I'm using as an associative array. This exists statically in a script block when the page loads: var salesWeeks = { "200911" : ["11 / 2009", "Fiscal 2009"], "200910" : ["10 / 2009", "Fiscal 2009"], "200909" : ["09 / 2009", "Fiscal 2009"], "200908" : ["08 / 2009", "...

Effective ways of finding an element in a Javascript array

I am using an array with titles. Each titles index corresponds to an id in a database which contains html for that given title. Lets say I have a string which contains one of the titles. title = "why-birds-fly"; titles[] // an array which contains all the titles To use the string "title" to get the corresponding id I could do: for (...

How do I read in a php array, in Objective-C?

In php I have: $result = mysql_query($query); // if successful query, return the records if ($result) { // if not empty result, return array of records if (mysql_num_rows($result)) { $records = array(); while ($row = mysql_fetch_assoc($result)) { $records[] = $row; } return $records; } } In Objective-C - After th...

Associative arrays in Shell scripts

We required a script that simulates Associative arrays or Map like data structure for Shell Scripting, any body? ...

How to determine if an associative array has a key?

In ActionScript 3, is there any convenient way of determining if an associative array (dictionary) has a particular key? I need to perform additional logic if the key is missing. I could catch the undefined property exception, but I'm hoping that can be my last resort. ...

Assign value from one associative array of php into another array

I have a variable $params which gets data from the database: $params = mssql_fetch_array($result) As far as I know, it is associative array. I want another array $tempParams to hold the value of this array. Can I assign it by using the following statement: $tempParams = $params In addition, do I need one single statement to decla...

php select function generates weird where clause

Hello I try to create a function to generate select functions. But the following code public function select($psTableName, $paFields ="",$paWhere=array()) { //initial return value $lbReturn = false; try { $lsQuery = "SELECT * FROM `"; $lsQuery .= $psTableName; $lsQuery .= "` "; if (!empty($paWhere)){ $lsQuery .= "WHERE...

php array to xml, using same array key names

We are using pear's xml serializer to turn our request arrays into XML to submit to other servers for an XML response. The problem is, for one of the attributes we will need to submit an XML similar to this <totalRooms> <Room> ... </Room> <Room> ... </Room> </totalRooms> How do we compile this in PHP arrays so the Ser...

multidimensional mixed associative/numeric array shifting

hi everyone, i have an issue i need to fix sooner than later. if i had the time to rewrite the entire script i would, but such is the life of a programmer, right? anywho, i've taken over a project and i have a multidimensional mixed associative/numeric array like so: Array ( [item1] => Array ( [dataset] => Array...

Javascript Object vs JScript Dictionary

Javascript Objects and JScript Dictionary are both associative Arrays obj = new Object ; dic = new ActiveXObject("Scripting.Dictionary") ; My question is... Is there any difference between them in terms of efficiency (either space or time) ?? In terms of functionality, I know a Dictionary is better because it allows more than just sca...

How can I put the results of a MySQLi prepared statement into an associative array?

I have a sql query and a mysqli prepared statement: $sql = 'SELECT photographers.photographer_id, photographers.photographer_name FROM photographers'; $stmt = $conn->stmt_init(); if ($stmt->prepare($sql)) { $stmt->bind_result($photographer_id, $photographer_name); $OK = $stmt->execute(); $stmt->fetch(); } How can...

Change an associative array into an indexed array / get an Zend_Table_Row_Abstract as non-associative

Hi out there in Stackland. I was wondering if there was either a function or an easy way to change an associative array into an indexed array. To elaborate, I'm using the Zend framework, and I've got a point in my site where I take out a row of an SQL table as an associative array. I've passed it to javascript via an echoed in JSON. ...

Checking if an associative array key exists in Javascript

How do I check if a particular key exists in a Javascript associative array? If a key doesn't exist and I try to access it, will it return false? Or throw an error? ...

How do I turn a PHP array into $keys and $values?

If I have an array as $keys => $values, how can I get two arrays of $keys and $values? ...

Array with associative values accessed numerically

Hello, I have an associative array that I might need to access numerically (ie get the 5th key's value). $data = array( 'one' => 'something', 'two' => 'else', 'three' => 'completely' ) ; I need to be able to do: $data['one'] and $data[0] to get the same value, 'something'. My initial thought is to create a class ...

Is there a way to order an associative array by how the keys are inserted with PHP?

Here's an example of what I mean: I have an array: array('type'=>'text', 'class'=>'input', 'name'=>'username', 'id'=>'username', 'value'=>'', 'size'=>'30', 'rows'=>'', 'cols'=>''); Then, I loop through it like so: $input = '<input '; foreach($input_array as $key => $value) { if(...

Comparing Multidimentional arrays in PHP

Hey everyone, I am trying to compare to multidimentional arrays, but I can't just use array_diff_assoc(). The arrays I am trying to compare are both associative arrays, and they are both sorted so the keys are in the same order. For the most part the arrays are identical in structure. I can't seem to figure out how to compare the ele...

Remove dupes/sort from a Array of Associative Arrays in PHP

I have a array of associative arrays aa[] = ('Tires'=>100, 'Oil'=>10, 'Spark Plugs'=>4 ); aa[] = ('Tires'=>454, 'Oil'=>43, 'Spark Plugs'=>3 ); aa[] = ('Tires'=>34, 'Oil'=>55, 'Spark Plugs'=>44 ); aa[] = ('Tires'=>454, 'Oil'=>43, 'Spark Plugs'=>45 ); aa[] = ('Tires'=>34, 'Oil'=>55, 'Spark Plugs'=>433 ); aa[] = ('Tires'=>23, 'Oil'=>33...

Formatting associative array declaration

When declaring an associative array, how do you handle the indentation of the elements of the array? I've seen a number of different styles (PHP syntax, since that's what I've been in lately). This is a pretty picky and trivial thing, so move along if you're interested in more serious pursuits. 1) Indent elements one more level: $arr...

SimpleXML, associative arrays, and XPath

Hey everybody, I have a question about xpath and arrays. What I was wondering was if it is possible to use xpath on some simpleXML and have it return an associative array of node names and their values. For example, say I have the following XML: <element1 page="1">blah</element1> <element2 page="1">blah blah</element2> <element3 page=...