associative-array

Associative arrays in C

人盡茶涼 提交于 2019-12-17 08:33:07
问题 I am implementing a way to transfer a set of data to a programmable dongle. The dongle is based on a smart card technology and can execute an arbitrary code inside. The input and output data is passed as a binary blocks that can be accessed via input and output pointers. I would like to use an associative array to simplify the data processing code. Everything should work this way: First the host application: // Host application in C++ in_data["method"] = "calc_r"; in_data["id"] = 12; in_data[

How to iterate over associative arrays in Bash

吃可爱长大的小学妹 提交于 2019-12-17 03:45:08
问题 Based on an associative array in a Bash script, I need to iterate over it to get the key and 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. 回答1: The keys are accessed using an exclamation point: ${!array[@]} , the values are accessed using ${array[@]} . You can iterate over the key/value pairs like this: for i in "${!array[@]}" do echo "key : $i" echo "value: ${array[$i]}" done Note the use of quotes

How to loop through an associative array and get the key? [duplicate]

若如初见. 提交于 2019-12-17 02:42:35
问题 This question already has answers here : PHP foreach loop key value (4 answers) Closed 5 months ago . 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 } 回答1: You can do: foreach ($arr as $key => $value) { echo $key; } As described in PHP docs. 回答2: If you use array

Create an Array with a KEY if values exists in two arrays?

六月ゝ 毕业季﹏ 提交于 2019-12-16 18:03:28
问题 I am having problem with handling arrays. I want to "compare" two arrays to see if there's matching "usernames" in both arrays. I am not sure if I am using in_array() function properly this is how my arrays look like: USER array 1: Array ( [0] => Array ( [username] => LNDP [station] => D08 ) [1] => Array ( [username] => ACMAN [station] => D06 ) [2] => Array ( [username] => VTER [station] => D13 ) ) //the users will have to be matched with memo_code $user = array(); while($row = mysqli_fetch

Create an Array with a KEY if values exists in two arrays?

本小妞迷上赌 提交于 2019-12-16 18:02:59
问题 I am having problem with handling arrays. I want to "compare" two arrays to see if there's matching "usernames" in both arrays. I am not sure if I am using in_array() function properly this is how my arrays look like: USER array 1: Array ( [0] => Array ( [username] => LNDP [station] => D08 ) [1] => Array ( [username] => ACMAN [station] => D06 ) [2] => Array ( [username] => VTER [station] => D13 ) ) //the users will have to be matched with memo_code $user = array(); while($row = mysqli_fetch

Javascript - Parsing INI file into nested associative array

拟墨画扇 提交于 2019-12-14 03:48:18
问题 I'm new to Javascript and I'm having trouble parsing an INI formatted file into nested objects. The file I have is formatted like this: ford.car.focus.transmission=standard ford.car.focus.engine=four-cylinder ford.car.focus.fuel=gas ford.car.taurus.transmission=automatic ford.car.taurus.engine=V-8 ford.car.taurus.fuel=diesel purchased=Ford Taurus I would like to have the structure look like this: { ford: { car: { focus: { transmission: 'standard', engine: 'four-cylinder', fuel: 'gas' } } {

What is the syntax for declaring a constant string[char] AA?

懵懂的女人 提交于 2019-12-14 03:46:05
问题 The following declaration: const(string[char]) AA1 = [ 'a' : "fkclopel", 'b' : "poehfftw" ]; void main(string args[]){} gives me: C:...\temp_0186F968.d(1,27): Error: non-constant expression ['a':"fkclopel", 'b':"poehfftw"] while it would work with other type kinds. 回答1: You can initialize associative array constants inside a module constructor: const /+ or immutable +/ (string [char]) AA1; static this () { AA1 = [ 'a' : "fkclopel", 'b' : "poehfftw" ]; } import std.stdio; void main () {writeln

PL/SQL: Selecting from a table into an assoc array

為{幸葍}努か 提交于 2019-12-14 03:43:36
问题 I am trying to select data into a pl/sql associative array in one query. I know I can do this with a hardcoded key, but I wanted to see if there was some way I could reference another column (the key column) instead. DECLARE TYPE VarAssoc IS TABLE OF varchar2(2) INDEX BY varchar2(3); vars VarAssoc; BEGIN SELECT foo, bar INTO vars(foo) FROM schema.table; END; I get an error saying foo must be declared when I do this. Is there some way to create my associate array in a single query or do I need

JavaScript - How to create an associative array that guarantees order?

夙愿已清 提交于 2019-12-14 00:12:51
问题 How can I create an associative array that guarantees order ? Object (not guarantee order): var obj = { "first":"first", "2":"2", "34":"34", "1":"1", "second":"second" }; for (var i in obj) { console.log(i); }; Result: 1 2 34 first second Array: var a = new Array(); a['first'] = "first"; a['2'] = "2"; a['34'] = "34"; a['1'] = "1"; a['second'] = "second"; console.log(a); // [1: "1", 2: "2", 34: "34", first: "first", second: "second"] for (var i in a) { console.log(i); }; Result: 1 2 34 first

Check If In_Array (in Recursive Associative Array)

我是研究僧i 提交于 2019-12-13 23:11:25
问题 I have an array similar to this: array(2) { [0]=> array(2) { ["code"]=> string(2) "en" ["name"]=> string(7) "English" } [1]=> array(2) { ["code"]=> string(2) "bg" ["name"]=> string(9) "Bulgarian" } } How do I check if the string Bulgarian is part of the above array, or alternatively if the lang code 'en' is part of the array? It would be great if I didn't have to use foreach to loop through the entire array and compare the string with each element['code'] or element['name']. 回答1: // $type