FAQ Database Discussion Community


How to empty the content of a key belonging to an associative array without unsetting the key in PHP?

php,arrays,multidimensional-array,associative-array,key-value
I've an array titled $aFilter as follows(Output of print_r($aFilter);): Currently only one internal array element is shown but it can contain many such elements. So consider the case with multiple internal array elements. Array( [0] => Array( [filter_id] => 84 [user_id] => 984 [item_id] => 244 [type_id] => user [feed_type]...

How to flatten a multilevel xml into List in java?

java,xml,xslt,jaxb,key-value
the objective is to flatten a multilevel repeated xml into xpaths at a leaf level ; so that we can store it in a Key-Value store and retrieve it . The assumption is that every repeating node will have a UID. generate a list of pairs where the Key is...

Adding key for average values in nested dictionary lists

python,python-2.7,dictionary,list-comprehension,key-value
I have a dictionary of keys of dates. Each date has a key:value pair of a project and a list of days. I would like to add an average metric to each date key, while removing outliers above 6. My code is close, but produces some screwy results. import numpy...

Assigning values to specific inputs from a hash

javascript,jquery,html,hash,key-value
Right now I'm working with the iTunes search API and trying to extract data from the key/value pairs of an album's tracklist and insert them into specific text inputs. I was able to accomplish this inside a table but due to how the app is currently setup it now calls...

Get KEY from JSON

javascript,json,key,key-value
Following JSON : https://api.myjson.com/bins/3yz34 I was thinking I might use an internal ID for a key (which simplifies looping through several entities and setting up data gathering) and use a value for display. However, I cannot get the value of the key. $.each(tabledata.Companies, function (){ company = this; alert(company); var...

Can't get correct Key-Value Pairs with Tika

java,apache,metadata,key-value,tika
I'm trying to get the Metadata Values from an Office Document and all it shows as key-value pair is this one: Content-Type: application/zip I just can't tell the issue in this one. Why does it only show the Content-Type? What i'm interested in are Keys like title. import java.io.FileInputStream; import...

Echo array based on distinct key

php,mysql,arrays,database,key-value
I have “ordered by” a database to be in ascending country order, then descending years. Each database record contains: countryname, year, details. There are many duplicate countries, but the years are different. For instance: Albania, 2000, details Albania, 1965, details Croatia, 2014, details Croatia, 2003, details Can’t figure out how...

Python3 Dictionary iterate through values?

python,loops,dictionary,key-value
Hey everyone I'm trying to write a program in Python that acts as a quiz game. I made a dictionary at the beginning of the program that contains the values the user will be quizzed on. Its set up like so: PIX0 = {"QVGA":"320x240", "VGA":"640x480", "SVGA":"800x600"} So I defined a...

Is there a more compact way to convert a sequence of (key,value) tuples into a {key:[value,..],..} dict?

python,python-2.7,dictionary,key-value
I have a sequence of tuples itemList in the format (key, value) and I want to convert the items in that list into a dict in the format {key : [value, ..], ..}. A specific key value may appear in itemList multiple times with a matching or new value, and...

PHP Autoincrement Array

php,arrays,indexing,key,key-value
I am having trouble with expanding my PHP array. Here is a sample of my code : <select name="PaymentCounts"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> </select> <?php $arr = array ('Client' => "Alex", 'BillNumber' => "123", 'PaymentCounts' => "1", 'Amounts' => array ('PaymentNumber' => array( array('Amount1' => "100.00",...

Combine multiple form input into key pair value array and add dimension to value

php,arrays,multidimensional-array,associative-array,key-value
I have following $_POST array : Array ( [fileName] => Array ( [0] => 8.png [1] => 2_OnClick_OK.jpg ) [fileLink] => Array ( [0] => https://www.filepicker.io/api/file/zZ993JyCT9KafUtXAzYd [1] => https://www.filepicker.io/api/file/1w3cKCW1TMmytb7md3XQ ) [Submit] => Submit File ) I got the above output after execution of following statement: print_r($_POST); die; // Code to...

Adding new key to dictionary overwrites all previously stored keys with new keys values

python,dictionary,key,key-value
I'm trying to use a for loop to generate random values for item prices, by changing the value of the item prices in a pre-defined dictionary. The new values of this pre-defined dictionary are then added to the end of another pre-defined dictionary so a history of prices can be...

How to get the array elements of a specific key from an associative array in following scenario?

php,arrays,multidimensional-array,associative-array,key-value
I've on associative array titled $group_list. When I print it using print_r($grouop_list) it prints following content: Pages_Component_Controller_List Object ( [data] => Array ( [0] => Array ( [vanity_url] => [page_type] => 1 [category_name] => Athletic [profile_server_id] => 0 [profile_user_image] => [is_liked] => 592 [page_id] => 174 [app_id] => 0 [view_id]...

HashMap Keys and Value comparison [closed]

java,dictionary,compare,key-value
I'm comparing HashMap value against the keys and replace if key is larger. The purpose is to update Finger Table of Chord System simulation. I have HashMap data: Key 0 with Values: [1,2,4,8,16] Key 3 with Values: [4,5,7,11,19] Key 7 with Values: [8,9,11,15,23] The desired outcome is such that for...

How to group multiple values in a key belonging to an object in Javascript?

javascript,function,group-by,key-value,lodash
I'm trying to replicate the groupBy method in lodash. Here is my code: var array = [1.1,1.3,2.3,2.5,3.1,3.5]; function groupBy (collection, func) { var result = {}; for (var i=0; i<array.length; i++) { var property = func(array[i]) if ((property in result) === property) { result[property] = array[i]; } else { result[property]...

Extracting key-value pairs from multiline text in java

java,regex,key-value,matcher,keyvaluepair
Consider the following multiline string: This is multiline text that needs to be correctly parsed into key-value pairs, excluding all other information. Section One: First key = Value One Second key = Value Two Section Two: Third key = Value Three Fourth key = Value Four Fifth key = Value...

Python: How to store multiple values for one dictionary key

python,list,dictionary,key,key-value
I want to store a list of ingredients in a dictionary, using the ingredient name as the key and storing both the ingredient quantity and measurement as values. For example, I would like to be able to do something like this: ingredientList = {'flour' 500 grams, 'tomato' 10, 'mozzarella' 250...

Get key value for selected option in select using jquery

jquery,json,select,key-value
I have a JSON like quarterJson = [{"quarter_id":1, "quarter":"Quarter 1", "end_date":'31.03.'}, {"quarter_id":2, "quarter":"Quarter 2", "end_date":'30.06.'}, {"quarter_id":3, "quarter":"Quarter 3", "end_date":'31.09.'}, {"quarter_id":4, "quarter":"Quarter 4", "end_date":'31.12.'}]; and using it populate options of a select box $('#quarterSel').empty(); $('#quarterSel').append('<option value="0">--Select--</option>'); $.each(quarterJson ,function(idx,ob){ $('#quarterSel').append ('<option...

Does Consul persist the Key Value store?

persistence,key-value,consul
I'm evaluating a few distributed key-value stores, and etcd and Consul looks both very promising. I am interested in service discovery, health monitoring and config services. I like the extra features that Consul gives, but I cannot determine whether it persists the Key-Value store when the service goes down? It...

Angularjs make post request to server with key value pair

angularjs,post,key-value
I am so beginner programming with Angularjs and I want to make post request to my server. On the server side I'am waiting data with key value pair. But when I try to post with the example code below I sent data in json so ı can't parse it on...

Sorting a key,value list in R by value

r,key-value
Given a list animals, call it m, which contains $bob [1] 3 $ryan [1] 4 $dan [1] 1 How can I sort this guy by the numerical value? Basically I'd like to see my code look like this m=sort(m,sortbynumber) $ryan [1] 4 $bob [1] 3 $dan [1] 1 I can't...

Why few numbers are getting added after calling serialize on an associative array in PHP?

php,arrays,serialization,associative-array,key-value
I've an array titled $aFilter. Upon serializing it few numbers are getting inserted into it. I'm not understanding why did it happen? Why did it insert the numbers and in which pattern? Can someone please guide me what actually this serialize() does and generates such kind of output in an...

count the words starts with a-z character using dictionary in python [closed]

python,list,dictionary,key-value,counting
Load the dictionary in python as a list from following url "https://cfstatic.org/static/words.txt". Using this word list, create a python dictionary (or an array if you are using php) with the following property : key : alphabet [a-z] value: number of words starting with that alphabet in the dictionary I...

JS and ExpressionEngine - Remove KV pairs by duplicate values only?

javascript,arrays,expressionengine,key-value
We're building a site with ExpressionEngine. We are running a SQL query to gather up all member IDs for a specific member group. After that, we are using EE tags to get data from a custom member field for each member ID. The ID and field data need to stay...

iOS- Update UITableViewCell information without reloading the row?

ios,uitableview,key-value,key-value-observing
Let's say you have a UITableView that displays a list of file metadata, and you want to show the download_progress of each file in a UILabel of a custom UITableViewCell. (This is an arbitrarily long list - thus dynamic cells will be reused). If you want to update the label...

saving key and value pairs swift

swift,key-value
I need a way to save key and value pairs in swift for my application. I am new to IOS programming, but I know Android and I am looking for something like shared preferences in android, but for swift. By "save," I mean that when the user quits out of...

Razor inside javascript key value declaration?

javascript,c#,razor,key-value
Given the need to extract data from a viewdata into a javascript key/value object: var stuff = { something : [@someVar.Prop2, @someVar.Prop3, etc] }; I want to make the key have the "name" of someVar.Prop1 so that: var stuff = { @someVar.Prop1 : [@someVar.Prop2, @someVar.Prop3, etc] }; Yet when I...

Angular - show key match with value

javascript,angularjs,templates,key-value
In my page I can select a type. The type has following structure: vm.types = { prospect: 'Prospekt', article: 'Artikel', photo: 'Photo', literature: 'Literatur' } In the template there is the select field which writes inside the current document the key of the type. <select data-ng-model="file.docType" data-ng-options="key as value for...

Join master table's data to a key/value table data in one SELECT

sql,sql-server,join,pivot,key-value
I have a table called Contacts that contains the columns Id FirstName LastName I have another table called ContactsExtra. It has the following columns: Id ContactId (FK refers to Contacts Id) PropertyId (FK refers to Properties Id) PropertyValue This is a Key/Value table that stores some extra contact properties. E.g....

How would I write a regex that matches the values following a string (to the next comma)

javascript,regex,csv,key-value
I have a csv of key=value pairs. How do I write a regex that matches only the value "[email protected]" (or any value following the key "password") without using lookbehind? system=blah, user=stevedave, [email protected], mylocation=amsterdam I have tried the following: [\n\r].*password=\s*([^\n\r]*) didn't match anything (from another SO thread) \bpassword=\s+(.*)$ just plain ol'...

Where I'm making a mistake in manipulating multi-dimensional array in following scenario?

php,arrays,multidimensional-array,associative-array,key-value
I've a large array titled $files. For understanding purpose I'm just putting small part of this array as follows(output of print_r($files);): Array ( [name] => Array ( [0] => course_error.png [1] => before_login.png ) [type] => Array ( [0] => image/png [1] => image/png ) [tmp_name] => Array ( [0]...

Find closest value to a given value in a dictionary c#

c#,dictionary,numbers,key-value
I have a dictionary and I want to find out which of the ‘key’ values is the closest to a given value, here is my dictionary below. Dictionary<double, int> dictionary = new Dictionary<double, int>(); dictionary.Add(2.4, 5000); dictionary.Add(6, 2000); dictionary.Add(12, 1000); dictionary.Add(24, 500); dictionary.Add(60, 200); dictionary.Add(120, 100); dictionary.Add(240, 50); dictionary.Add(600, 20);...

Hashmap that keeps original key/value when duplicate key entered

java,hashmap,key-value,duplicate-entry
Is it possible for a Hashmap to keep its original key/value pair when a duplicate key is entered? For example, let's say I have something like this: Map<String, String> map = new HashMap<String, String>(); map.put("username","password1"); map.put("username","password2"); I want the original key/value pair - username, password1 to be kept and not...

What I'm doing wrong in following array manipulation in foreach loop?

php,arrays,foreach,associative-array,key-value
I've an array titled $photos as follows: Array ( [0] => Array ( [fileURL] => https://www.filepicker.io/api/file/UYUkZVHERGufB0enRbJo [filename] => IMG_0004.JPG ) [1] => Array ( [fileURL] => https://www.filepicker.io/api/file/WZeQAR4zRJaPyW6hDcza [filename] => IMG_0003.JPG ) ) Now I want to create a new array titled $values as follows : Array ( [vshare] => Array...

Can I create dynamic pivot query from key value table with different data types?

sql-server,pivot,key-value,dynamic-sql
I have a key-value pairs table. I have created a script using dynamic sql that pivots the table correctly. However, the keys have different data types. Is there a way to cast the keys during or after the pivot dynamically? I can have the data types in the same key-value...

Search for key in Map when the values are in ArrayList [closed]

java,arraylist,collections,hashmap,key-value
I am new to the collections in Java , I have a HashMap<String, List<String>>. I want to search for a key from the Map when a value is given. The map stores the data of a state as key and its cities as the list. So it is assumed that...

Storing entities with dynamic set of properties in a table (and using fixed columns or key-value tables)

sql,sql-server,database,database-design,key-value
I would like to store people's information in the database (table). Every person can have a different set of properties. I would like to store all these properties. But creating fixed number of columns does not make my application scalable. So, another approach is to store these values inside key-value...

Why the array is not getting modified after executing following code?

php,arrays,multidimensional-array,associative-array,key-value
I've an array titled $aRows as follows : Array ( [0] => Array ( [is_liked] => [comment_id] => 262 [parent_id] => 0 [type_id] => document [item_id] => 160 [user_id] => 991 [owner_user_id] => 991 [time_stamp] => 1425364320 [update_time] => 0 [update_user] => [rating] => [ip_address] => 125.17.118.118 [author] => 1592...

how to set app.config key value?

c#,app-config,key-value
I want to set some keys in .NET console application's app.config file. Like : <add key="Success" value="<Status>Success</Status>"/> <add key="Error" value="<Status>Error</Status>"/> But it's not allowing me to do that set values in <> brackets.Can we set key values like this ?...

Strange behaviour of .item() method of Scripting.Dictionary class in VBA

vba,excel-vba,dictionary,key-value
As I have programmed before in Python language I'm accustomed to use the Dictionary structure of data. Now, I need to program in VBA, and I want to use the same structure, if it is possible. In order to learn the methods in VBA I've wrote this procedure. First .count...

Best way to store a list of java objects in Redis

java,redis,key-value,jedis
It would be great if someone could suggest me on what would be the best way to store a list of java objects in Redis. Currently, I'm converting the java objects into json strings and storing those strings in Redis and I have a set in Redis to keep track...

Delete a key-value pair in BerkeleyDB

dictionary,key-value,berkeley-db
Is there any way to delete key-value pair where the key start with sub-string1 and ends with sub-string2 in BerkeleyDB without iterating through all the keys in the DB? For ex: $sub1 = "B015"; $sub2 = "5646"; I want to delete $key = "B015HGUJJ75646" Note: It is guaranteed that there...

How to get array from JSON data and convert it into desired new array format?

php,arrays,json,associative-array,key-value
I'm getting following JSON request data : data = "{\"photo\":[{\"fileURL\":\"https:\\/\\/www.filepicker.io\\/api\\/file\\/RqAN2jZ7ScC8eOx6ckUE\",\"filename\":\"IMG_0003.JPG\"},{\"fileURL\":\"https:\\/\\/www.filepicker.io\\/api\\/file\\/XdwtFsu6RLaoZurZXPug\",\"filename\":\"IMG_0004.JPG\"}]}"; I want to make an array from the above JSON data into following format : Array ( [vshare] => Array ( [IMG_0003.JPG] => Array ( [0] => https://www.filepicker.io/api/file/RqAN2jZ7ScC8eOx6ckUE ) [IMG_0004.JPG] => Array ( [0] =>...

How to get a value which is a list from redis key-value store in golang?

go,redis,key-value
I am writing a function in golang to get the value from redis db by passing the key. The value is a list. I am using 'GET' redis command to get the value. But it is giving me error. You can find below the code, func GetValue(key string) []string {...

Python - Count the number of dictionary keys with values that match a certain lookup string

python,dictionary,key-value
I have a dictionary as follows: Key Value 5zd {'status': 'Outofservice', 'date': '201505'} 8km {'status': 'Peaking', 'date': '201505'} erg {'status': 'Outofservice', 'date': '201505'} xrg {'status': 'Booming', 'date': '201505', 'rate': 18.691588785046733, 'mean': 4} 86e {'status': 'Constant', 'date': '201505', 'rate': -9.6810933940774486, 'mean': -17} 4ld {'status': 'Constant', 'date': '201505', 'rate': -4.7619047619047619, 'mean': -1}...