w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
Converting Cell array of function handle into a single array of function handle
Use func2str to get the function definitions in string and use str2func to get the desired function, if A is the cell array containing the function handles: B = strcat(regexprep(cellfun(@func2str, A, 'uni', 0), '^@(x)', ''), ';'); F = str2func(strcat('@(x) [', B{:}, ']')); Now F contains the desired function handle.

Categories : Matlab

Save DB query into an array and group all entries of user_id into one array entry
Use it: I could not describe in detail for time limitation <?php $highscoreData []= (object) array( "user_id" => 1, "username" => 'name1', "user_firstname" => "First Name 1", "user_lastname" => "Last Name 1", "user_point" => 20 ); $highscoreData []= (object) array( "user_id" => 1, "username" => 'name1', "user_firstname" => "First Name 1", "user_lastname" => "Last Name 1", "user_point" => 50 ); $highscoreData []= (object) array( "user_id" => 2, "username" => 'name2', "user_firstname" => "First Name 2", "user_lastname" => "Last Name 2", "user_point" => 80 ); $user_point_sum = array(); $users = array(); foreach($highscoreData as $array) { //check if user_id

Categories : PHP

Handle all of an array's events
Made use of the AddHandler keyword, which I didn't know existed. for i = 0 to _batInputs.Length -1 AddHandler _batInputs(i).SelectionChanged, AddressOf HandleSelectionChangedEvent next Private Sub HandleSelectionChangedEvent 'do something End Sub

Categories : Arrays

Best way to handle array in object in handlebars
{{reviewers.length}} within that loop will give you the number of reviewers (size of the array). AFAIK there is no helper for easily joining an array with a delimiter (eg. getting a comma separated list of your reviewers), but you can write a custom helper such as here: GitHub feature request Here's a solution someone posted for implementing a join helper: Handlebars.registerHelper('join', function(val, delimiter, start, end) { var arry = [].concat(val); delimiter = ( typeof delimiter == "string" ? delimiter : ',' ); start = start || 0; end = ( end === undefined ? arry.length : end ); return arry.slice(start, end).join(delimiter); });

Categories : Javascript

Cell Array and function handle
I think it's a displaying issue, rather than a functional issue. Doing this: for i = 1:2 if i == 1 F{i}= @(x) x(i)+x(i+1); else F{i}= @(x) x(i-1)-x(i)+2; end end actually gives the correct results: >> F{1}([1 2 3 4]) ans = 3 % == x(1)+x(2), i==1 >> F{2}([1 2 3 4]) ans = 1 % == x(1)-x(2)+2, i==2 But the functions are displayed "incorrectly": >> F F = @(x)x(i)+x(i+1) @(x)x(i-1)-x(i)+2 If you want them to be displayed correctly as well, you'll have to get messy: for i=1:2 if i == 1 F{i} = str2func(['@(x)x(' num2str(i) ')+x(' num2str(i+1) ')']); else F{i} = str2func(['@(x)x(' num2str(i-1) ')-x(' num2str(i) ')+2']); end end Results: >> F F = @(x)x(1)+

Categories : Matlab

Using JQuery/JavaScript how would I group values in an array of objects and create a new array of objects from the groups
If you're willing to use Underscore.js, this becomes pretty trivial. Assuming data is your original list of json objects, this will achieve what you're after: var groups = []; var by_grade = _.groupBy(data, function(obj) { return obj['grade'] }); _.each(by_grade, function(objs, grade) { var group = {}; group['grade'] = grade; group['ids'] = _.pluck(objs, 'id'); group['versions'] = _.pluck(objs, 'version'); // Use the following if the value is known to be // the same for all grouped objects group['platform'] = objs[0]['platform']; // And the rest... groups.push(group); }); _.groupBy() will group your objects by grade, resulting in two objects with the keys X and A, whose values are lists of objects with the corresponding grades. You can then loop ove

Categories : Javascript

bash: unexpected array member handle
This seems to be a bug that has been fixed, possibly this one: (from the bash ChangeLog -- changes between bash-4.2-alpha and bash-4.1-release) Fixed a bug in arithmetic expansion that caused the index in an array expansion to be evaluated twice under certain circumstances. Worksforme: $ echo "${BASH_VERSINFO[*]}" 4 2 42 1 release i586-pc-linux-gnu $ i=4; echo "${BASH_VERSINFO[i++]}"; echo "$i" release 5 $ i=4; echo "${BASH_VERSINFO[i++]%e}"; echo "$i" releas 5

Categories : Arrays

HTTPArty/Rails: How to handle the Response array
It seems that the API returns a response with a Content-Type different from application/json. You can check that by printing: puts result.content_type If so, the HTTParty parser may be interpreting the response as a plain text; And, thus, the code result[0]['param1'] evaluates to nil Maybe you can try to parse the desired value into @a with: @a = JSON.parse(result)[0]['param1'] Don't forget to require the json library require 'json' Good luck!

Categories : Javascript

CakePHP - how to handle double quote in conditions array
You must be mistaken. The error must be somewhere else. The resulting SQL query does contain LIKE 'foo "bar"' But that escaping is actually intentional. I will still turn up the DB entry with foo "bar" - I just tried it myself with cake2.3/2.4. So CakePHP is working correctly.

Categories : Cakephp

Is this the correct way to handle C multi-dimensional array navigation
One would typically use a for loop in C. int main() { char td[][4] = { {0,1,2,3}, {4,5,6,7}, {8,9,10,11}, {12,13,14,15}, {16,17,18,19}, {20,21,22,23} }; int rows = sizeof(td) / sizeof(td[0]); int cols = sizeof(td[0]) / sizeof(td[0][0]); /* Print first element in each 'row' */ for (int row = 0; row < rows; row++) printf("first element: %u ", td[row][0]); return 0; } However, the code you have written does work.

Categories : C

Matrix multiplication of a Array Cell of function handle
There is no way other than: writing your own class that supports multplications and/or additions of function_handles and doubles converting everything to string, manipulating the strings, and convert back to function handle (see the wonderful version Mohsen came up with) Do not actually create A*B but rather just evaluate it (just compute A*cellfun(@(f)f(y),B) for some y) Manually copy-pasting the expressions ...something else undoubtedly ugly. Just out of curiosity, could you please explain why you 'need' this operation?

Categories : Matlab

How can I handle either an array or a single object with the same MVC controller method?
Because you accept collection so you need to send collection via array in js: You can create array even for one element You can create another action method to accept element not array HTH

Categories : C#

How to handle array of objects in node.js using express and mongodb
Well, I found out how to do it. It rather suited my app to use embedded sub than to have another Schema and collection so I deleted the Sub collection and edited the Main collection to: var Main= new Schema({ subs: [ content: String, date: Date ] }); exports.create = function(req, res) { Main.update({_id: req.body.mid}, {$push: {subs: {content: req.body.content}}}, {upsert: true},function(err, main) { res.end(); }); };

Categories : Node Js

Using dynamic array to handle collisions in hash tables
One advantage of a linked list over a dynamic array is that rehashing can be accomplished more quickly. Rather than having to make a bunch of new dynamic arrays and then copy all the elements from the old dynamic arrays into the new, the elements from the linked lists can be redistributed into the new buckets without performing any allocations. Additionally, if the load factor is small, the space overhead of using linked lists may be better than the space overhead for dynamic arrays. When using dynamic arrays, you usually need to store a pointer, a length, and a capacity. This means that if you have an empty dynamic array, you end up needing space for two integers and a pointer, plus any space preallocated to hold the elements. In an empty bucket, this space overhead is large compared

Categories : Algorithm

ANDROID Handle large amount of buttons with array?
User "Horschtele" answered it in a perfect way but he deleted his answer on his own (don't know why). Horschtele, if you read that, I just want to say that this solution is just perfect! I have to (or at least I think I have to) do this for every tableRow but this saves me an infinite amount of time. Thanks again Horschtele (are you german? :)) My modified version of Horschtele's answer if you already have your buttons in a table: ViewGroup container = (ViewGroup) findViewById(R.id.tableRow1); for(int i=0; i<container.getChildCount();i++){ System.out.println(container.getChildCount()); Button button = (Button)container.getChildAt(i); button.setOnTouchListener(this); } (don't wonder about the println, you can easily

Categories : Android

How to handle an array from an ajax input to work with jquery autocomplete?
I am afraid you will need to tranform it to a json compatible format. Get rid of the first and last bracket Split the chain by the comma character Remove the apostrophees and brackets in the resulting array and you will have a clean array with the values you need. At this point you can loop through the array transforming to json manually or use a parser that will format it in a more automatic way.

Categories : Jquery

Java how to handle "Unchecked cast" for Array from Object
You cannot do it without a warning. You are casting an Object to some other class, and even if the Object is an instance of ArrayList you don't know it's generic type.

Categories : Java

Group values from array
So, you want to tranpose an array. Here's a magical way of transposing rectangular arrays: array_unshift($array, null); $array = call_user_func_array('array_map', $array);

Categories : PHP

Codeigniter group by array
You need to sort the result by country, city and then venue. When you loop, you can do the following <?php $lastCountry = null; $lastCity = null; $query = $this->db->query("SELECT country, city, venue FROM venues ORDER BY country, city, venue"); // CI query foreach($list = $query->result_array()) { if($list['country'] != $lastCountry) { $lastCountry = $list['country']; print "<h1>".$list['country']."</h1>"; } if($list['city'] != $lastCity) { $lastCity = $list['city']; print "<h2>".$list['city']."</h2>"; } print "<p>".$list['venue']."</p>"; }

Categories : Mysql

How to handle passing/returning array pointers to emscripten compiled code?
The expected format of Module.cwrap does allow for 'array's to be passed into the function, but will assert on result and fail if you attempt to return an array displayArrayA=Module.cwrap('displayArray','array',['array']) displayArrayA([1,2,3]) // Assertion failed: ccallFunc, fromC assert(type != 'array') A second restriction of this is that incoming arrays are expected to be byte arrays, meaning you would need to convert any incoming double arrays into unsigned 8-bit numbers displayArrayA=Module.cwrap('displayArray','number',['array']) displayArrayA(new Uint8Array(new Float64Array([1,2,3]).buffer)) Calling the method this way will invoke your function, temporarily copying your arrays to the Emscripten stack which will be reset after your invoked function's execution, making the ret

Categories : Javascript

handle incrementing number of array ID in duplicated form field set (regex)
You can store the item in the data portion of html (if its unique for each tr/checkbox) retrieve it that way and then increment it, then add the brackets in. HTML <tr data-name="myName"></tr> javascript newRow.find("input[type=checkbox]").each(function(x, item) { var name = $(item).data('name'); //this give you the name if it unique var newName = name + x + '[]' // this give final result });

Categories : Javascript

Use linq to group by array element
var results = db.Schedules.GroupBy(x => x.Id) .Select(g => new { .Id = g.Key, .Data = g.SelectMany(x => x.MyArray) .GroupBy(x => x.Date) .Select(g2 => new { Amount = g2.Sum(x => x.Amount), Date = g2.Key }) .ToArray() });

Categories : Arrays

MongoDB - Aggregation, group by an array value
Unfortunately, that isn't possible using aggregation with your schema. The problem is that aggregation is meant to operate over values in an array that are being selected by the $group clause and those elements have all the data needed. Your setup separates what you want to group by and what you want to sum. You could use a mapReduce job to do what you want with your schema. http://docs.mongodb.org/manual/core/map-reduce/ should be able to get you started. Let me know if you have any other questions. Best, Charlie

Categories : Mongodb

PHP shuffle array by group of values
With this user defined function shuffle_assoc you can shuffle your array before sorting. function shuffle_assoc(&$array) { $keys = array_keys($array); shuffle($keys); foreach($keys as $key) { $new[$key] = $array[$key]; } $array = $new; return true; } $array = array('peter' => 100 , 'paul' => 100 , 'mary' => 50 , 'andrew' => 50 , 'bill' => 50 , 'jason' => 10 , 'sofia' => 10); shuffle_assoc($array); asort($array); array_reverse($array); var_dump($array);

Categories : PHP

PHP Array : "group by" then count maximum
Assuming that your array is something like the following: $arr = array( 1 => array( 'Name' => 'Tom', 'Date' => '2013-05-19', 'Points' => '23'), 2 => array( 'Name' => 'Tom', 'Date' => '2013-05-20', 'Points' => '11'), 3 => array( 'Name' => 'Tom', 'Date' => '2013-05-21', 'Points' => '40'), 4 => array( 'Name' => 'Jack', 'Date' => '2013-05-19', 'Points' => '34'), 5 => array( 'Name' => 'Jack', 'Date' => '2013-05-20', 'Points' => '15'),

Categories : PHP

SQL 'Group By' Clause Changes Array Results
The Group By clause consolidates the matched rows into one row. Thus when you are grouping on the cable_no you get two rows, since you have two unique cable_no (80010 and 90017). For you drop down if you wanted to eliminate duplicates you should use the unique clause on the field that you want to filter duplicates for.

Categories : PHP

Get all object from a "group" in PHP from JSON array
Use foreach. $json = json_decode( $input, true ); $elems = $json['canvas']['Elements']; foreach( $elems as $key => $value ) { echo "{$key} is an array/object: "; echo var_dump( $value ); } You could use array_keys() if you need to know what keys are inside $value or you could another foreach loop, but I am assuming you will have at least some clue what keys could be in $value.

Categories : PHP

Play Framework send array/list for client-side code to handle
I used something similar: <script> var items = new Array(); @for((result: String, index) <- results.zipWithIndex) { items[@index] = "@result"; } </script> But I agree that it's a bit kludgy, especially when you need to escape special chars... // Multiline js escape can be done this way: .replaceAll(" ", "\\ ")

Categories : Scala

javascript extjs array group multi value
I don't understand you very well, but i think that you are trying to group on a grid for one field: sencha api: grid grouping You need to add one feature on your grid view definition: features: [{ id: 'group', ftype: 'groupingsummary', groupHeaderTpl: '{name} ({rows.length})', //print the number of items in the group hideGroupedHeader: false }], One example on Sencha Api: Example

Categories : Javascript

Group Array Multidimensional by index and values
This seems really ugly, but works. Stacked foreach version: http://3v4l.org/Dve0M $rst=array(); foreach($arr as $ele) { foreach($rst as $i=>$candidate) { $key=null; foreach($ele as $k=>$subarr) { if(isset($candidate[$k]) && $candidate[$k]==$subarr) { $key=$i; break; } } if(!empty($key)) { break; } } if(!empty($key)) $rst[$key]["total"]+=1; else $rst[]=array_merge($ele,array("total"=>1)); } print_r($rst); No foreach version: http://3v4l.org/qUU3a /* just to ensure the array is sorted. * if the array is already pre-sorted, * skip this part. */ usort($arr,function($a,$b){ return strcmp(json_encode($a),json_en

Categories : PHP

Group array of hashes by multiple keys
I would do it this way: def group_hashes arr, group_fields arr.group_by {|hash| hash.values_at(*group_fields).join ":" }.values.map do |grouped| grouped.inject do |merged, n| merged.merge(n) do |key, v1, v2| group_fields.include?(key) ? v1 : (v1.to_f + v2.to_f).to_s end end end end You can group by multiple keys by joining them with some delimiter, see arr.group_by {|hash| hash.values_at(*group_fields).join ":" } And I suppose, you don't need sum_field, because generally all fields that aren't grouped should be summed up.

Categories : Ruby

Codeigniter group by and create multidimensional array
Try this, you may have to change it slightly: function get_job(){ $data = array(); $data = $this->db->get('job')->result_array(); foreach( $data as $key=>$each ){ $data[$key] = $this->db->where('idadministrator', $each['idadministrator'])->get('administrator')->row_array(); $data[$key]['artwork'] = $this->db->where('idjob', $each['idjob'])->get('artwork')->result_array(); } return $data; }

Categories : PHP

Function to group equivalent elements of an array
Can you not just pass _.groupBy() and expression which will differentiate your inputs properly? p1 = {name:'Anna', birthYear: 1990, birthPlace: 'Alaska', gender: 'female', hasCar: true, hasChildren: false} p2 = {name:'John', birthYear: 1990, birthPlace: 'Alaska', gender: 'male', hasCar: true, hasChildren: false} p3 = {name:'Dora', birthYear: 1980, birthPlace: 'Hawaii', gender: 'female', hasCar: true, hasChildren: true} p4 = {name:'Lumi', birthYear: 1980, birthPlace: 'Hawaii', gender: 'female', hasCar: false, hasChildren: false} p5 = {name:'Jack', birthYear: 1990, birthPlace: 'Alaska', gender: 'male', hasCar: false, hasChildren: false} people = [p1, p2, p3, p4, p5] groups = _.groupBy(people, (x) -> '' + x.birthYear + x.birthPlace + x.gender) console.log groups http://jsfiddle.net/v

Categories : Javascript

How to store group member in string Array
If you just want to store an array of Strings without knowing the number of Strings to store use an ArrayList. //create the arraylist ArrayList<String> memberNames = new ArrayList<String>(); // add the memeber name to the array memberNames.add(attributes.get("member"));

Categories : Java

Group Rows in HTML Table from PHP Array
Create a different array. $truecats = array(); foreach ($cats as $pieces) { if (!isset($truecats[$pieces['category']]) { $truecats[$pieces['category']] = array(); } $truecats[$pieces['category']][] = $pieces['value']; } // You can then loop over this array: foreach ($truecats as $name => $values) { echo "<tr><td rowspan=" . count($values) . ">$name</td>"; foreach ($values as $val) { echo "<td>$val</td>"; } }

Categories : PHP

Group and add values in a vector/array in java
Why not use the split() function to parse out your delimited string? Take a look at: http://pages.cs.wisc.edu/~hasti/cs302/examples/Parsing/parseString.html Regardless of how you parse, it looks like all your data is in triplets where only the first and last values matter: a xyz 12 b efg 13 a pqr 45 c erer 18 a vbv 27 d tag 40 c etc... resolves to: a 12 b 13 a 45 c 18 a 27 d 40 ... Assuming that, you could loop over the array in threes and accumulate the values as you go. In pseudocode: for( i = 0; i < array.length(); i+=3) { if(!map.containsKey( array[i] )) map.put( array[i], array[i+2] ); else map.put( array[i], map.get( array[i] ) + array[i+2] ); } For the map, you could use a Hashmap<String,int>, I suppose.

Categories : Java

group data of multiple fields in an array
Try this: <div class="module">Module1</div> <input type="hidden" value="module1" name="module[0][module_id]"> <input type="hidden" value="title" name="module[0][title]"> <input type="hidden" value="some text" name="module[0][text]"> <div class="module">Module2</div> <input type="hidden" value="module2" name="module[1][module_id]"> <input type="hidden" value="another title" name="module[1][title]"> <input type="hidden" value="another text" name="module[1][text]"> ... And you can access it like so: foreach ($_POST['module'] as $module) { echo $module['module_id']; echo $module['title']; echo $module['text']; }

Categories : PHP

Using C# linq, How can i group by specific item in array?
var projectsByApp = projects.SelectMany(p => p.Applications .Select(a => new { p, a })) .GroupBy(x => x.a) .Select(g => new { Application = g.Key, Projects = g.Select(x => p).ToList()) }) .ToList(); Or even simpler to read: var projectsByApp = (from p in projects from a in p.Applications group p by a into g select new { Application= g.Key, Projects = g.ToList() }).ToList(); Both queri

Categories : C#

Altering the Kinetic group childrens array
--- Very uncommon requirement --- Is there no workaround in your code instead of messing with kinetic's internal arrays? It's almost always a bad idea to mess with the internals of a library script Having said that, I took a quick look at the kinetic's Container.js code. https://github.com/ericdrowell/KineticJS/blob/master/src/Container.js This is the internal add child method: add: function(child) { var children = this.children; this._validateAdd(child); child.index = children.length; child.parent = this; children.push(child); this._fire('add', { child: child }); // chainable return this; }, Note that child.index property is set to the position of the child in the array of children. Properly resetting each child.index is probably yo

Categories : Javascript

reformat existing array to group items together
This should do it, assuming the only choices are front and back. $result = array(array('name' => 'front', 'prev' => array()), array('name' => 'back', 'prev' => array())); foreach ($info as $data) { $i = (strpos(strtolower($data['label']), "front") !== false) $result[$i]['prev'][] = array('name' => $data['name']; } $newinfo = array('approval' => $result;

Categories : PHP



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.