w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Nested template foreach performance
First, your fiddle isn't rendering the nested template because you forgot your quotes around the inner template name. Your code : template: { name : ContactLine, foreach: Contacts } should have the name in quotes like this : template: { name : "ContactLine", foreach: Contacts } With that fixed, 1500 items can be a sizable amount of rendering depending on what's going on in the template, although I've worked on projects where we're pushing about that much data in a table without too much trouble. Our slow-down was actually mapping from raw JSON to the view models; rendering was acceptably fast. With that said, it's not too hard to add paging, even if you want to keep all that data on the client-side for quick sorting. If your bottleneck is actually the render and not mapping, th

Categories : Knockout Js

What is the performance differences between using parallel.foreach and task inside foreach loop?
How many tasks are you running? Just the creation of a new task could require a significant amount of time if you're looping enough. i.e., the following runs in 15 ms for the first block, and over 1 sec for the 2nd block, and the 2nd block doesn't even run the task. Uncomment the Start and the time goes up to nearly 3 sec. The WaitAll only adds a small amount. static class Program { static void Main() { const int max = 3000000; var range = Enumerable.Range(0, max).ToArray(); { var sw = new Stopwatch(); sw.Start(); Parallel.ForEach(range, i => { }); sw.Stop(); Console.WriteLine(sw.ElapsedMilliseconds); } { var tasks = new Task[max]; var sw = new Stopwat

Categories : C#

PHP: Pull values foreach() nested array, run function, return a 2nd level nested array
foreach ($array as $key => $value){ $array[$key]['restaurants'] = work($value['id'],$value['name']); } function work($id,$name){ $results = array(); ///process data return $results; }

Categories : PHP

How to break nested foreach loop then go to parent foreach loop on c#
The only way to this directly is with a goto. Another (better) option is to restructure until the problem goes away. For instance by putting the inner code (while + foreach) in a method and use return to get back.

Categories : C#

foreach loop List performance difference
Basically, there's a small amount of extra indirection - both for the test via a delegate, and for the iterating part. Given just how little work is being done per iteration, that extra indirection is relatively expensive. That's neither surprising nor worrying, in my view. It's the kind of micro-optimization you can easily perform if you're in the rare situation of it being significant in your real-world application. In my experience it's pretty rare for this sort of loop to be a significant bottleneck in the app. The normal approach should be: Define performance requirements Implement the functional requirements in the clearest, simplest way you can Measure your performance against the requirements If performance is found wanting, investigate why and only move away from clarity as lit

Categories : C#

php foreach nested table
Here is the code I fix for you: Assuming the number of elements in $spec is same as or more than the number of elements in $tunnid. In coder's perspective, count($spec) >= count($tunnid). <table style="width: 600px" class="slicedTable"> <tr> <th>Spetsialist</th> <th>Tunnid</th> </tr> <?php $i = 0; foreach($specs as $specName => $spec): ?> <tr> <td><?php echo $specName; ?></td> <td><?php echo isset($tunnid[$i]) ? $tunnid[$i] : '-'; ?></td> </tr> <?php $i++; endforeach; ?> </table> Not really an elegant solution, I admit.

Categories : PHP

Arrays and nested foreach
Assuming they have matching keys for the loop: foreach( $name as $key => $value) { echo $value[$key] . $family[$key] . '<br />'; } This will go through each match for $name and print it out, and then print out the corresponding $family with it. I don't think you want to hardcode [1]. If you do, I'm a little confused and would like to see a var_dump of both $name and $family for clarification.

Categories : PHP

nested foreach loop in PHP 5
You have a typo: echo '<div>'."<img src='$src' width='100'/>".'<h1>'. $item->make.' '.$item->model.'</h1>'. should be echo '<div>'."<img src='$src' width='100'/>".'<h1>'. $item->make.' '.$item->model.'</h1>'; Note the ";" at the end of the echo.

Categories : PHP

nested FOREACH statements
For fastest execution a UDF would be best. In pure Apache Pig it would be nice if you could do count on (group, lt, ln) before creating a relation with your schema. It woul be something like this (it is just a pseudo script, might need some debugging) Assuming load schema is (id, lt, ln) inpt = LOAD ....... as (id, lt : chararray, ln : chararray); grp1 = GROUP inpt BY (id, lt, ln); data1 = FOREACH grp FLATTEN(inpt), COUNT(data1) as cnt; data2 = GROUP data_wtih_count BY id; --data2: {group: chararray,data1: {(id, lt: chararray,ln: chararray, cnt : int)}} most_probable_pair = FOREACH data2 { ord = ORDER data1 BY cnt ASC; top = LIMIT ord 1; GENERATE group, top.(ln, lt); } Or you could flatten data2 and data1 and start with grp1.

Categories : Apache

loop through nested QHash with foreach
Should be working like this: QHash<QString, int> myHash0; myHash0["test0"]=0; myHash0["test1"]=1; QHash<QString, int> myHash1; myHash1["test0"]=0; myHash1["test1"]=1; QHash<QString, QHash<QString, int> > myHashList; myHashList["Hash0"] = myHash0; myHashList["Hash1"] = myHash1; QHash<QString, int> h; foreach(h , myHashList) { qDebug()<<h["test0"]; }

Categories : C++

PHP foreach: replace value in nested array
Just use the reference operator &to pass values by reference: foreach($nested_array as &$values) { foreach($values as &$value) { do_something($value); } } unset($values); // These two lines are completely optional, especially when using the loop inside a unset($value); // small/closed function, but this avoids accidently modifying elements later on.

Categories : PHP

Nested foreach statements to access
You have an extra } right before the second foreach. That one is closing the method, so the second foreach is out of the method definition and that is a syntax error.

Categories : C#

Nested foreach put into a string array in C#
I'd suggest using a List instead of initializing a string[]. They're just easier to work with. Llike this: var locations = new List<string>(); foreach (ContentAPI.BasicHotelMedia item in rawData) { ... locations.Add(item.BasicSellingLocation); } OtherMethod(locations.ToArray());

Categories : C#

Echo nested foreach with no duplicates PHP
May be that will help: $rgLinks = array_combine($array1, $array2); foreach($rgLinks as $sClass=>$sHref) { echo('<li><a href="'.$sHref.'" class="'.$sClass.'">Visit Site</a></li>'); }

Categories : PHP

Nested foreach to display over rows
u are going too complex on it try this : int row = 1; @foreach (var article in Model) { @if(row == 1) @:<div class="row"> <div class="spanthird col"> <div class="well"> <article> <h3>@article.UrlStringDisplay</h3> <div class="date">@article.Date.ToString("dd MMMM yyyy")</div> <a href="@Url.RouteUrl("PressReleases", new {id = article.UrlString, Action = "article", Controller = "PressReleases"})" class="btn btn-primary">Read more</a> </article> </div> </div> @if(row == 3)

Categories : C#

nested foreach with knockout binding?
You can't access "OptInfo" this way because of the structure of your JSON. You are passing an array of one object to the observableArray. Here is the structure of this object: { "TupleArray":[ { "OptInfo":{ "Version":"B", "Name":"csk_profile" }, "Parameter":[ { "Value":"1", "Name":"min SampleCopunt" } ] }, { "OptInfo":{ "Version":"A", "Name":"Dml_profile" }, "Parameter":[ { "Value":"2", "Name":"min SampleCopunt" } ] } ] } So, this object, which becomes the context in your for each loop does not have a "OptInfo" property. The object only contains an array of two objects ("TupleArray").

Categories : Javascript

Possibilities and nested foreach loops C#
Try a recursive method. A small example : public List<Table> assignToTable(List<Person> invited, List<Table> tables) { if(!tables.HasRoom) return tables; else { assign(tables,invited) //code to add a person to a table assignToTable(invited, tables); } } If I were you I'll create a object taht represent you tables with a propertie to know if there is still some room avaiblable. This will assign to every people a table without any foreach. Then in you main you could have a method that will rearrange the tables in all the way possible : Table 1 Table 2 Table 3 Then Table 1 Table 3 Table 2 ... Table 3 Table 2 Table 1 and call the recursive method on those lists and you will have all the possibility where poeple can sit...

Categories : C#

Nested foreach loops - anything more efficient?
You can squeeze a bit more performance from your loops by using the values by reference: foreach ($arraykey as $columnname => &$value) { Hence the &$value, but beware, every time you do something to $value after that, it will affect the original $arraykey[$columnname] value. Also, not sure you're nesting the foreach correctly. I would move the ending bracket for the nested foreach down: // $value passed by reference foreach ($arraykey as $columnname => &$value) { // Pass $field_entity_id by reference foreach ($records as &$field_entity_id) { $fieldinsertloop = "('registration', 'reg_type', 0,".$field_entity_id.",".$field_entity_id.", 'und', 0,'".$value."','".$value."')"; $sql = "INSERT INTO " .str_replace("multi_reg", "field_data", $colu

Categories : PHP

wpf nested foreach index array out of bounds
I would suggest using a jagged array, that way if you encounter a situation where you have more than 10 columns in a line it won't throw an out of bound error. I'd also recommend using File.ReadAllLines as that will return an array of all the lines in the file. Something like this (not tested) should get you going: string[] fileData = File.ReadAllLines(@"C:Usersapr13mpsipDocumentsVisual Studio 2010ProjectsiStellarMobileiStellarMobilePuzzleeducational.txt"); string[] lineValues; int row = 0; int col; string[][] rowcol = new string[fileData.Length][]; foreach (string line in fileData) { lineValues = line.Split(new string[]{ ',' }, StringSplitOptions.None); rowcol[row] = new string[lineValues.Length]; col = 0; foreach (string value in splits) { rowcol[row

Categories : C#

Wordpress Simple Fields nested foreach
Found a solution : <?php $getfields = simple_fields_get_post_group_values(get_the_id(), "Field group name", true, 1); $count = 0; if($getfields["Field1"][0]!="") { foreach($getfields["Field1"] as $options) { ?> <?php $imgsrc = wp_get_attachment_image_src($getfields["Field1"][$count], 'thumbnail'); ?> <li> <div class="small-12 large-6 columns text"> <?php echo($getfields["Field2"][$count])?> </div> <div class="small-12 large-6 columns"> <img src="<?=$imgsrc[0]?>" /> </div> </li> <?php $count++; }} ?> Field group name : Just type the name of the field, not the slug Field 1 and Field2 : im not sure if here goes the name or the slug but i have named the slug and the name the same because i was in

Categories : PHP

Nested ForEach with afterRender callbacks in knockout.js
Because you are inside of a context of a foreach you need to use $parent to access your arCategories method which is declared one "level up". <div data-bind="foreach: {data: categories, afterRender: $parent.arCategories}"> <span data-bind="text: $data"></span> </div> Demo JSFiddle. See also Note 2: Using $index, $parent, and other context properties and the Binding context pages in the documenation for further information. Sidenote: If you only want a comma delimited list you can just use the array.join() method: <div data-bind="text: categories.join()"></div> Demo JSFiddle.

Categories : Javascript

How/should I replace nested foreach with one linq query?
Controls.OfType<GroupBox> .SelectMany(x => x.Controls.OfType<Label>) .Where(x => x.Tag != null && x.Tag.ToString() == "answer") .ToList() .ForEach(x => x ForeColor = (x.Name.Replace("lbl", "") == rb.Name) ? afterSelectColor : beforeSelectColor); Notice that the ForEach() method is not part of LINQ. It's a member of the List<T> class. LinQ is a functional feature, therefore it's methods are not supposed to affect the source objects. That's why there's no ForEach() in LINQ. Edit: If you don't like the use of List<T>.ForEach(), then you may also do it this way: var labels = Controls.OfType<GroupBox> .SelectMany(x => x.Controls.OfType<Label>) .Where(x => x.T

Categories : C#

Returning from a function in nested Parallel.Foreach
As the two loops can be executed on different threads you have to introduce shared state between the controlling thread and the running threads handling the ForEach calls. In this case a boolean can be assumed to be atomic updateable and therefor threadsafe so no locking is needed. In the if condition set the result bool to true and then call state.Stop(); to signal that the outerloop should end. When it does control is returned to the calling thread while result is now true and that value is returned to the caller. bool MyNestedFunction() { bool result = false; // shared state! Parallel.ForEach (ListofStrings_A, (OuterString, state) =>//loopA { Parallel.ForEach (ListofStrings_B, InnerString => //loopB { string FirstTemperedString = Temperedstring

Categories : C#

Nested foreach loops, PHP, how do I manipulate the values?
You need to use the reference syntax (& prefix): foreach ($final_array as &$final_array_val) { } unset($final_array_val); Note that the unset is required to break the reference to the last value. Read more here.

Categories : PHP

Populate array inside nested foreach PHP
$display=array();//declare the array outside the loop foreach ($array as $arrays){ foreach ($arrays as $elem) { unset($elem['id']); //Removes id key unset($elem['idno']); //Removes idno key foreach ($elem as $last_array => $last2_array) { $display[$last_array] = $last2_array; } } }

Categories : PHP

Foreach loop not working - is this a nested array?
Have you tried going into the first array with this? foreach( $groups[0] as $group ) { ?> <?php echo $group['title'] ?> <?php echo $group['day'] ?> <?php if ($group['time']) { ?> <?php } ?> If possible, you could try two foreach loops: foreach( $groups as $tmp ) { ?> foreach ($tmp as $group) { <?php echo $group['title'] ?> <?php echo $group['day'] ?> <?php if ($group['time']) { ?> <?php } ?> <?php } ?>

Categories : PHP

LINQ expression instead of nested foreach loop
Console.WriteLine(String.Join(Environment.NewLine, pro.TokenList.SelectMany(s => s) )); Or, Console.WriteLine(String.Join(Environment.NewLine, from arr in pro.TokenList from s in arr select s ));

Categories : C#

nested foreach loops in R to update common array
foreach loops are used for their return value, like lapply. In this way they are very different from for loops which are used for their side effects. By using the appropriate .combine functions, the inner foreach loop can return vectors which are combined row-wise into a matrix by the outer foreach loop: x <- foreach(i=1:8, .combine='rbind') %dopar% { foreach(j=1:2, .combine='c') %do% { l <- runif(1, i, 100) i + j + l } } You can also use the nesting operator: %:%: x <- foreach(i=1:8, .combine='rbind') %:% foreach(j=1:2, .combine='c') %dopar% { l <- runif(1, i, 100) i + j + l } Note that set.seed probably won't do what you want, since it is being performed on the local machine, while the random numbers are generated in different R ses

Categories : R

Write nested XML file with powershell in foreach loops
using $xmlWriter.WriteEndElement() instead of $xmlWriter.WriteEndElement should fix your problem same problem in this post

Categories : Xml

How to access a nested Dictionary<> objects in a foreach loop
That's because the value of the string key is not a list. Change the declaration of the Dictionary to Dictionary<string, List<Dictionary<string, string>>> dict; if that's what you want. Or you could just grab the dictionary inside the first foreach loop like this: Dictionary<string, string> val = dict[key]; and use it from there. But either way, you're trying to iterate against something that's not enumerable. I think you may have the Dictionary defined like you want -you just don't need an inner loop.

Categories : C#

Why does not the data-binding work? (using nested foreach loops)
This can't work : self.pc_listOfExpenses()[claimID] = JSON.parse(data); Because you are modifying the internal array of the observableArray(). I am not sure, but you could try this : var items = self.pc_listOfExpenses(); items[claimID] = JSON.parse(data); self.pc_listOfExpenses(items); I hope it helps.

Categories : Javascript

how can i get array in proper format from this foreach and nested if condition in php?
Update to this one. From : array_push($color1,$color); $items = array($color1); To array_push($color1, $color); if(!empty($color1)) { $items[] = $color1; } And $items = array() before loop.

Categories : PHP

Unexpected results when binding in nested foreach using Breeze.js
Can't tell. Looks basically right .. except for a markup error (below). The JSON is nice to have but I can't tell what you actually have for Category entities after the query completes. Before we take a next step, what happens when you fix the markup? Markup mistake You don't want the parentheses after "Name" in the children template. It should be <div data-bind="text: ' - ' + Name"></div> <!-- NO PARENS AFTER NAME --> as it is in your Fiddle. Cleaner success callback While you're here, you might consider this alternative syntax which simply replaces the inner array with the query results array; no iteration needed. .then(function (data) { vm.categories(data.results); console.log("here: " + data.results.length); -- produces 9 }); })

Categories : Knockout Js

knockoutjs pass parameters in nested foreach binding
Calling .bind creates a new function that is executed with a specific context and arguments. So, the result of .bind is a function, which you could then execute by adding () after it. However, in this case (using the text binding) it looks like you want the output of the function call, so you could simplify it to just: data-bind="text: $root.checkNetwork('something')"

Categories : Knockout Js

Performance of nested select
About first query: first query will evaluate the inner select first and then apply the filter to the outer query. That not so simple. In SQL is mostly NOT possible to tell what will be executed first and what will be executed later. Because SQL - declarative language. Your "nested selects" - are only visually, not technically. Example 1 - in "someTable" you have 10 rows, in "otherTable" - 10000 rows. In most cases database optimizer will read "someTable" first and than check otherTable to have match. For that it may, or may not use indexes depending on situation, my filling in that case - it will use "indexedField" index. Example 2 - in "someTable" you have 10000 rows, in "otherTable" - 10 rows. In most cases database optimizer will read all rows from "otherTable" in memo

Categories : SQL

Powershell Issues Comparing two Arrays using Nested Foreach loop
The issue is with how you are looping through the records. You are comparing the first record in the new users list with all of the list of users in the second list. This basic if/else statement causes you to get the following result. for ex.: Loop 1: compare: fadbd34 = fadbd34 -> Active User Loop 2: compare: fadbd34 = fadbk45 -> Inactive User Loop 3: compare: fadbd34 = fadoo78 -> Inactive User ... This causes you to get 1 correct active user, and a list of 5 inactive users. Every time the user does not match a user in the old list, it stores it as an inactive user. The code that I got working (After cleaning it up, removing the unnecessary array references (If you split the string, and store it in a variable, you don't need an array reference), fixing variable names, and chan

Categories : Powershell

Powershell Nested Foreach loop giving incorrect results
I think the problem is that you are trying to match every item in one file to every other item in the other file so each run of the outer loop wil result in one possible and lots of non matches. Why not use the Compare-Object instead like so: Compare-Object -ReferenceObject $oldusers -DifferenceObject $newusers -IncludeEqual | % { if($_.SideIndicator -eq '==') {$f = 'found'} else {$f = 'NotFound'} if($_.SideIndicator -eq '<=') {$a = 'Old'} if($_.SideIndicator -eq '=>') {$a = 'New'} "New User_id $($_.InputObject) $f in $a user list" } Another alternative would be to just do one loop and use -contains instead of -ieq.

Categories : Powershell

Improving performance of a Nested Loop
Here's a one-line LINQ option. Not the best in terms of performance (it iterates multiple times). Still worth noting. var result = myArray .OrderByDescending(i => myArray.Count(i2 => i2 >= i && i2 <= i + 5)) .First();

Categories : C#

Sql nested queries execution performance
Possible this be helpful for you - SELECT M.UserID, Browser = SUM(X.Browser) FROM ( SELECT UserName , Browser = MAX(Browser) FROM [PCMDBSERVER].[MISTestPCM_Raw].[dbo].[PCM_Log_FilterSwitchData] WHERE [DateTime] BETWEEN '20130613 12:00:00' AND '20130613 23:59:59' GROUP BY UserName ) X JOIN ( SELECT UserName , UserID FROM dbo.PCM_Stat_UserRepository WHERE MachineID = 'All' ) M ON X.UserName = Y.UserName GROUP BY M.UserID

Categories : SQL

Simplify conventional foreach nested loop using linq & lambda expression
You could do this; not sure if it's more readable tho! var coll3 = (from selected in coll2 from item in coll1 where selected == item select item).ToList();

Categories : C#



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