associative-array

What's the difference between pls_integer and binary_integer?

我怕爱的太早我们不能终老 提交于 2019-11-27 05:42:07
问题 I've inherited some code which is going to be the base for some additional work. Looking at the stored procs, I see quite a lot of associative-arrays. Some of these are indexed by binary_integers, some by pls_integers. Are there any differences between the two? I had a look at the documentation, but apart from this line: The PL/SQL data types PLS_INTEGER and BINARY_INTEGER are identical. For simplicity, this document uses PLS_INTEGER to mean both PLS_INTEGER and BINARY_INTEGER . I couldn't

In PHP, is there a function that returns an array made up of the value of a key from an array of associative arrays?

本秂侑毒 提交于 2019-11-27 05:39:30
问题 I'm sure this question has been asked before, my apologies for not finding it first. The original array: [0] => Array ( [categoryId] => 1 [eventId] => 2 [eventName] => 3 [vendorName] => 4 ) [1] => Array ( [categoryId] => 5 [eventId] => 6 [eventName] => 7 [vendorName] => 8 ) [2] => Array ( [categoryId] => 9 [eventId] => 10 [eventName] => 11 [vendorName] => 12 ) My hoped for result out of: print_r(get_values_from_a_key_in_arrays('categoryId', $array)); [0] => 1 [1] => 5 [2] => 9 I'm just

How to add an array value to the middle of an associative array?

本秂侑毒 提交于 2019-11-27 05:23:12
问题 Lets say I have this array: $array = array('a'=>1,'z'=>2,'d'=>4); Later in the script, I want to add the value 'c'=>3 before 'z' . How can I do this? Yes, the order is important. When I run a foreach() through the array, I do NOT want this newly added value added to the end of the array. I am getting this array from a mysql_fetch_assoc() The keys I used above are placeholders. Using ksort() will not achieve what I want. http://www.php.net/manual/en/function.array-splice.php#88896 accomplishes

Value objects vs associative arrays in PHP

天大地大妈咪最大 提交于 2019-11-27 05:21:44
问题 (This question uses PHP as context but isn't restricted to PHP only. e.g. Any language with built in hash is also relevant) Let's look at this example (PHP): function makeAFredUsingAssoc() { return array( 'id'=>1337, 'height'=>137, 'name'=>"Green Fred"); } Versus: class Fred { public $id; public $height; public $name; public function __construct($id, $height, $name) { $this->id = $id; $this->height = $height; $this->name = $name; } } function makeAFredUsingValueObject() { return new Fred(1337

Union of dict objects in Python [duplicate]

三世轮回 提交于 2019-11-27 04:21:33
问题 This question already has an answer here: How do I merge two dictionaries in a single expression? 41 answers How do you calculate the union of two dict objects in Python, where a (key, value) pair is present in the result iff key is in either dict (unless there are duplicates)? For example, the union of {'a' : 0, 'b' : 1} and {'c' : 2} is {'a' : 0, 'b' : 1, 'c' : 2} . Preferably you can do this without modifying either input dict . Example of where this is useful: Get a dict of all variables

Read associative array from json in $_POST

你。 提交于 2019-11-27 04:21:08
问题 I am using jQuery to post a json object to my php application. jQuery.post("save.php",JSON.stringify(dataToSend), function(data){ alert(data); }); The json string as pulled from firebug looks like this { "data" : [ { "contents" : "This is some content", "selector" : "DIV.subhead" }, { "contents" : "some other content", "selector" : "LI:nth-child(1) A" } ], "page" : "about_us.php" } In php I am trying to turn this into an associative array. My php code so far is <?php $value = json_decode

How to insert a new key and value in multidimensional array?

南楼画角 提交于 2019-11-27 02:24:44
问题 Following is the output of my multidimensional array $csmap_data Array ( [0] => Array ( [cs_map_id] => 84 [cs_subject_id] => 1 ) [1] => Array ( [cs_map_id] => 85 [cs_subject_id] => 5 ) [flag] => 1 ) Initially there was no [flag] => 1 key-value in the array, I added it to the array $csmap_data . But I want to add the [flag] => 1 in the above two array elements, not as a separate array element. In short I wanted following output : Array ( [0] => Array ( [cs_map_id] => 84 [cs_subject_id] => 1

Multidimensional associative arrays in Bash

夙愿已清 提交于 2019-11-27 01:36:33
问题 I'm trying to create a multidimensional associative array but need some help. I have reviewed the page suggested in this SO answer but it confused me even more. So far here is what I have: The script: #!/bin/bash declare -A PERSONS declare -A PERSON PERSON["FNAME"]='John' PERSON["LNAME"]='Andrew' PERSONS["1"]=${PERSON[@]} PERSON["FNAME"]='Elen' PERSON["LNAME"]='Murray' PERSONS["2"]=${PERSON[@]} for KEY in "${!PERSONS[@]}"; do TMP="${PERSONS["$KEY"]}" echo "$KEY - $TMP" echo "${TMP["FNAME"]}"

Hash tables VS associative arrays

心已入冬 提交于 2019-11-27 00:08:04
问题 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 want to. But I don't know how to start. Can anyone give me some samples of using it, for example, how to realize a dictionary application (like ABBYY Lingvo) using hash-tables? And finally I would like to know what is the difference between hash-tables and associative arrays in PHP, I mean which technology should I use and in which situations? If I

PHP combine two associative arrays into one array

試著忘記壹切 提交于 2019-11-26 22:04:33
$array1 = array("$name1" => "$id1"); $array2 = array("$name2" => "$id2", "$name3" => "$id3"); I need a new array combining all together, i.e. it would be $array3 = array("$name1" => "$id1", "$name2" => "$id2", "$name3" => "$id3"); What is the best way to do this? Sorry, I forgot, the ids will never match each other, but technically the names could, yet would not be likely, and they all need to be listed in one array. I looked at array_merge but wasn't sure if that was best way to do this. Also, how would you unit test this? Samuel Cook array_merge() is more efficient but there are a couple of