key-value

Using preg_match on a multidimensional array to return key values arrays

那年仲夏 提交于 2019-11-27 18:57:30
问题 I have an array that is structured as such: $data = array( "abc"=>array( "label" => "abc", "value" => "def", "type" => "ghi", "desc" => "jkl", ), "def"=>array( "label" => "mno", "value" => "qrs", "type" => "tuv", "desc" => "wxyz", ), ); I want to use preg_match with a foreach loop to perform a search on the arrays contained in $data and return the nested arrays of key value pairs. 回答1: Something like this? <?php $data = array( "abc"=>array( "label" => "abc", "value" => "def", "type" => "ghi",

The default for KeyValuePair

两盒软妹~` 提交于 2019-11-27 17:28:24
I have an object of the type IEnumerable<KeyValuePair<T,U>> keyValueList , I am using var getResult= keyValueList.SingleOrDefault(); if(getResult==/*default */) { } else { } How can I check whether getResult is the default, in case I can't find the correct element? I can't check whether it is null or not, because KeyValuePair is a struct. Try this: if (getResult.Equals(new KeyValuePair<T,U>())) or this: if (getResult.Equals(default(KeyValuePair<T,U>))) pholpar You can create a general (and generic) extension method, like this one: public static class Extensions { public static bool IsDefault<T

jQuery get values from inputs and create an array

本小妞迷上赌 提交于 2019-11-27 14:34:47
问题 I have many inputs on a page. I want to create an associative array with each input's name and value using jQuery. I've tried: <input class="activeInput" type="text" name="key1" value="red"> <input class="activeInput" type="text" name="key3" value="France"> inputValues = $('.activeInput').val(); EDIT - Thanks to the insightful comments, it seems maybe creating an object is a better way to go. Any suggestions on how to create an object instead? 回答1: You can use .each() to iterate over the

Create a Dictionary in xaml?

╄→尐↘猪︶ㄣ 提交于 2019-11-27 14:20:00
Pseudo example: <Window> <Window.Tag> <x:Dictionary KeyType="{x:Type sys:String}" ValueType="{x:Type sys:Int32}"> <sys:DictionaryEntry Entry="{sys:DictionaryEntry Key0, 000}"/> <sys:DictionaryEntry Key="key1" Value="111"/> <sys:DictionaryEntry> <sys:DictionaryEntry.Key> <sys:String>Key2<sys:String> </sys:DictionaryEntry.Key> <sys:DictionaryEntry.Value> <sys:Int32>222</sys:Int32> </sys:DictionaryEntry.Value> </sys:DictionaryEntry> </x:Dictionary /> </Window.Tag> </Window> Thomas Levesque You can't use the Dictionary<TKey, TValue> class directly in XAML, because there's no way to specify the

How do I create a keyValue pair (display field) by combining/having two fields in CakePHP 3?

会有一股神秘感。 提交于 2019-11-27 14:07:02
I need help getting two values (for human friendly dropdown) in a key-value pair using find or get or anything else. I need help with the simplest method of doing this in CakePHP. Here's my attempt: in my controller $users = $this->LocationsUser->Users->find('list', [ 'limit' => 1, 'keyField' => 'id', 'valueField' => ['first_name', 'last_name'] ])->where(['id' => $id]); In my view echo $this->Form->input('user_id', [ 'options' => $users, 'type' => 'select', 'multiple' => false, ]); The result on my drop-down: <option value="10">Fabian;Pankiers</option> See I need a result without the semicolon

Cassandra time series data

雨燕双飞 提交于 2019-11-27 13:14:10
问题 We are looking at using Cassandra to store a stream of information coming from various sources. One issue we are facing is the best way to query between two dates. For example we will need to retrieve an object between datetime dt1 and datetime dt2. We are currently considering the created unix timestamp as the key pointing to the actual object then using get_key_range to query to retrieve? Obviously this wouldn't work if two items have the same timestamp. Is this the best way to do datetime

Can the key in a Java property include a blank character?

吃可爱长大的小学妹 提交于 2019-11-27 12:43:24
问题 We are getting properties (that we can not influence) out of a database and want to access them by a key/value mapping. We are facing the problem that one of the property keys includes a blank character. foo bar = barefoot This is - correctly - interpreted as follows key: foo value: bar = barefoot Is there a way to include the blank in the key so that it's not interpreted as the delimiter? I guess this behaviour is just like intended, but I thought I could give it a try here. 回答1: As it seems

Swap key with value JSON

瘦欲@ 提交于 2019-11-27 11:44:53
I have an extremely large JSON object structured like this: {A : 1, B : 2, C : 3, D : 4} I need a function that can swap the values with keys in my object and I don't know how to do it. I would need an output like this: {1 : A, 2 : B, 3 : C, 4 : D} Is there any way that I can do this would manually created a new object where everything is swapped? Thanks jPO function swap(json){ var ret = {}; for(var key in json){ ret[json[key]] = key; } return ret; } Example here FIDDLE don't forget to turn on your console to see the results. ES6 version: static objectFlip(obj) { const ret = {}; Object.keys

通过Map的Key-Value映射到实体对象

半世苍凉 提交于 2019-11-27 11:25:51
static void setFieldValue(Map<String,Object> maps,Object obj){ if (maps != null){ Iterator keys = maps.keySet().iterator() while(keys.hasNext()){ String key = (String)keys.next() String value = maps.get(key) try{ Field field = obj.getClass().getDeclaredField(key) field.setAccessible(true) field.set(obj, field.getType().getConstructor(field.getType()).newInstance(value)) }catch(Exception e){ } } } } 来源: https://www.cnblogs.com/xiaoyutongxue/p/11361481.html

How can I get key's value from dictionary in Swift?

拈花ヽ惹草 提交于 2019-11-27 11:01:55
问题 I am early bird in swift. I have a dictionary.I want to get my key's value.Object for key method is not worked for me.Can anybody help me please? This is my dictionary; var companies = ["AAPL" : "Apple Inc", "GOOG" : "Google Inc", "AMZN" : "Amazon.com, Inc", "FB" : "Facebook Inc"] for (name) in companies.key { println(companies.objectForKey("AAPL")) } 回答1: With this method you see the key and the value. var companies = ["AAPL" : "Apple Inc", "GOOG" : "Google Inc", "AMZN" : "Amazon.com, Inc",