associative-array

MySQL/PHP: return two columns as an associative array as key => value pairs

陌路散爱 提交于 2020-01-07 05:45:43
问题 I apologize if this might have been asked before, or if this isn't even possible, but here is what I am hoping to get from a particular table using MySQL. Say, I have the following table: +-------------+------------------+ | property | value | +-------------+------------------+ | style | unisex | | color | blue | | type | small | +-------------+------------------+ I would like to be able to fetch the two columns property and value as an associative array from MySQL , so the end result would

How to copy a ksh associative array?

夙愿已清 提交于 2020-01-07 04:22:27
问题 Is there a way to copy an associative array? I realize that regular arrays can be copied easily with a one liner as such: set -A NEW_ARRAY $(echo ${OTHER_ARRAY[*]}) but doing so with associative arrays just gives you the values in that manner. I know about nameref but I'm interested in knowing if there's a way of copying the array such that the original array isn't affected. 回答1: untested: typeset -A NEW_ARRAY for key in "${!OTHER_ARRAY[@]}"; do NEW_ARRAY["$key"]="${OTHER_ARRAY[$key]}" done

How to model associative arrays in UML?

怎甘沉沦 提交于 2020-01-07 03:51:14
问题 I know there are some related questions about this question, such as this, this and this, but no one of them really helped me. My array keys are dynamic, so I can't create an additional class holding this attributes (like done in second linked question). The idea of my concept is to hold instances of classes as follows: $instances = [ "nameOfClass" => [ //instances of "nameOfClass" ], "nameOfClass2" => [ //instances of "nameOfClass2" ] //some more classes ]; But I don't know how to model

compare two associative array and display the difference

旧巷老猫 提交于 2020-01-06 14:58:30
问题 I have the following Two array results coming from MySQL query result. Array One (Orignal-Data): Array ( [w_a] => Array ( [0] => Array ( [cod] => CRR [pr] => LL [aid] => VM2254 [gender] => m [title] => ) ) [w_a_ml] => Array ( ) [w_a_ol] => Array ( ) [w_a_rl] => Array ( [0] => Array ( [rol] => 1 ) ) ) Array Two (Changed-Data) Array ( [w_a] => Array ( [0] => Array ( [cod] => CRR [pr] => LL [aid] => VM2254 [gender] => f [title] => Mr ) ) [w_a_ml] => Array ( [0] => Array ( [wl] => 255 [care] =>

Awk code with associative arrays — array doesn't seem populated, but no error

只愿长相守 提交于 2020-01-06 08:48:29
问题 Question: Why does it seem that date_list[d] and isin_list[i] are not getting populated, in the code segment below? AWK Code (on GNU-AWK on a Win-7 machine) BEGIN { FS = "," } # This SEBI data set has comma-separated fields (NSE snapshots are pipe-separated) # UPDATE the lists for DATE ($10), firm_ISIN ($9), EXCHANGE ($12), and FII_ID ($5). ( $17~/_EQ\>/ ) { if (date[$10]++ == 0) date_list[d++] = $10; # Dates appear in order in raw data if (isin[$9]++ == 0) isin_list[i++] = $9; # ISINs appear

Group together different parts of array from CSV using PHP?

筅森魡賤 提交于 2020-01-06 08:39:56
问题 I have an array from a CSV import that I want to group together based on an ID. The structure is as follows: Each row is a measure and a comment added to a submission. There can be multiple rows for one submission. For example, if there are 3 measures, then the headline submission data will be repeated 3 times, with different comments/measure details. //this is the submission id [1] => Array [0] => Array ( [0] => 1 [1] => Lot [2] => Lot Submission [3] => Lot Submission [4] => Lot Submission

Array containing keys and associative array, how to make a relation

自闭症网瘾萝莉.ら 提交于 2020-01-06 08:17:18
问题 I have an array which contains the path to a specific value from an other array, to make it a bit more clear, here is an exemple. My array containing the keys which I'll call $params Array ( [0] => paths [1] => assets [2] => js ) And here is my associative array which I'll call $config Array ( [paths] => Array ( [assets] => Array ( [js] => /assets/js [css] => /assets/css ) ) [library] => Array ( [js] => jQuery ) ) So how could I use my array 1 to access the value in my array 2? I tried

Get ASSOC array value by numeric index

人走茶凉 提交于 2020-01-06 04:05:38
问题 In all the examples of Codeigniter queries at https://www.codeigniter.com/user_guide/database/results.html, I find that the name of the field must be known to get its value. $query = $this->db->query("SELECT title,name,body FROM table"); foreach ($query->result() as $row) { echo $row->title; echo $row->name; echo $row->body; } For example, if I want to get the title , I will perform row->title . Is there a way to get the title using an index e.g. like $row[0] ? 回答1: Use result_array function

Arranging a multi-dimensional array

廉价感情. 提交于 2020-01-04 11:09:12
问题 I have a PHP array that looks like this: http://pastie.org/1346063 (see pastie for array example) What I want to do is re-sort that array into another array that is sorted by each array's [votes][POINTS] sub-array numerically descending. The array with the highest [votes][POINTS] value will be the first listed in the main array. 回答1: Using the usort() function we can create our own comparison function: function cmp($a, $b) { if($a['votes']['POINTS'] == $b['votes']['POINTS']) { return 0; }

How to write empty associative array ({}) to MongoDB from PHP

前提是你 提交于 2020-01-04 03:18:39
问题 When I try to insert empty associative array ( hashmap / dictionary / dict / {} ) to MongoDB from PHP, it is always inserted as non-associative empty array ( list / [] ). Can I force associative array? Example: $m = new Mongo('mongodb://localhost:27017'); $db = $m->selectDB('test'); $collection = $db->selectCollection('test'); // 1: inserts [] $d = array( 'x' => array() ); $collection->insert($d); // 2: inserts [] $d = array( 'y' => array('a'=>'123') ); unset($d['y']['a']); $collection-