Search Results

Search found 15239 results on 610 pages for 'array population'.

Page 61/610 | < Previous Page | 57 58 59 60 61 62 63 64 65 66 67 68  | Next Page >

  • php - usort or array_multisort?

    - by Simpson88Keys
    Trying to sort the array below by memnum in ascending order, and I'm a bit confused which is better to use... usort or array_multisort? I was thinking usort because it's multidimensional? Does anyone have an example of this? Array ( [0] => Array ( [memnum] => 3236467423 [mid] => 1104881300 [fname] => JOHN [lname] => DOE [add1] => OMITTED [add2] => [city] => CHESTERFIELD [state] => MI [zip] => 48051 [age] => 50 ) [1] => Array ( [memnum] => 3258467922 [mid] => 1105121457 [fname] => JANE [lname] => DOE [add1] => OMITTED [add2] => [city] => CHESTERFIELD [state] => MI [zip] => 48051 [age] => 50 ) [2] => Array ( [memnum] => 3237769108 [mid] => 1104489312 [fname] => BOB [lname] => DOE [add1] => OMITTED [add2] => [city] => CHESTERFIELD [state] => MI [zip] => 48051 [age] => 50 ) )

    Read the article

  • Iterate through directory filenames using JavaScript on ASP.NET C#

    - by Gal V
    Hello all, I'm trying to read all filenames from a specified (server- not client) folder, and insert all the filenames into a javascript Array. It should behave like the Directory.GetFiles method in ASP.NET C#. I created a new array, and I just need the loop method (Javascript or jQuery) to iterate in the specific folder, and insert all the filenames into the array. Thanks all helpers!

    Read the article

  • Reversing permutation of an array in Java efficiently

    - by HansDampf
    Okay, here is my problem: Im implementing an algorithm in Java and part of it will be following: The Question is to how to do what I will explain now in an efficient way. given: array a of length n integer array perm, which is a permutation of [1..n] now I want to shuffle the array a, using the order determined by array perm, i.e. a=[a,b,c,d], perm=[2,3,4,1] ------ shuffledA[b,c,d,a], I figured out I can do that by iterating over the array with: shuffledA[i]=a[perm[i-1]], (-1 because the permutation indexes in perm start with 1 not 0) Now I want to do some operations on shuffledA... And now I want to do the reverse the shuffle operation. This is where I am not sure how to do it. Note that a can hold an item more than once, i.e. a=[a,a,a,a] If that was not the case, I could iterate perm, and find the corresponding indexes to the values. Now I thought that using a Hashmap instead of the the perm array will help. But I am not sure if this is the best way to do.

    Read the article

  • Create associative multi-dimensional array

    - by Mike
    Hi, I have 3 variables, each one holding a different information and send values from a text file dynamicaly. I want to put them in a Associative multi-dimensional array. let's say : $product sends car, truck, train, etc. $price sends 1000, 3000, 1500, etc. $year sends 1997, 1980, 2008, etc. How to create a function which generates an array as follow, when i execute print_r(myarray): Array ( [0] => Array ( [product] => car [price] => 1000 [year] => 1997 ) [1] => Array ( [product] => truck [price] => 3000 [year] => 1980 ) [2] => Array ( [product] => train [price] => 1500 [year] => 2008 )) and so on. Does anyone know how to do this? Many thanks, Mike,

    Read the article

  • What is the Proper approach for Constructing a PhysicalAddress object from Byte Array

    - by Paul Farry
    I'm trying to understand what the correct approach for a constructor that accepts a Byte Array with regard to how it stores it's data (specifically with PhysicalAddress) I have an array of 6 bytes (theAddress) that is constructed once. I have a source array of 18bytes (theAddresses) that is loaded from a TCP Connection. I then copy the 6bytes from theAddress+offset into theAddress and construct the PhysicalAddress from it. Problem is that the PhysicalAddress just stores the Reference to the array that was passed in. Therefore if you subsequently check the addresses they only ever point to the last address that was copied in. When I took a look inside the PhysicalAddress with reflector it's easy to see what's going on. public PhysicalAddress(byte[] address) { this.changed = true; this.address = address; } Now I know this can be solved by creating theAddress array on each pass, but I wanted to find out what really is the best practice for this. Should the constructor of an object that accepts a byte array create it's own private Variable for holding the data and copy it from the original Should it just hold the reference to what was passed in. Should I just created theAddress on each pass in the loop

    Read the article

  • Write Parcelable for ArrayList<String []> in android?

    - by sugan.s
    I just created model with String array and array list of string array.Like this public class LookUpModel implements Parcelable { private String [] lookup_header; private ArrayList<String []> loookup_values; public void writeToParcel(Parcel dest, int flags) { dest.writeStringArray(getLookup_header()); }; } I have implemented parcelbale then write for String [] but how to do for the ArrayList<String []> and that values need to pass to another activity.Thanks in advance.

    Read the article

  • Why wouldn't `new int[x]{}` be valid???

    - by dboarman-FissureStudios
    In MonoDevelop I have the following code which compiles: int[] row = new int[indices.Count]{}; However, at run-time, I get: Matrix.cs(53,53): Error CS0150: A constant value is expected (CS0150) (testMatrix) I know what this error means and forces me to then resize the array: int[] row = new int[indices.Count]{}; Array.Resize(ref row, rowWidth); Is this something I just have to deal with because I am using MonoDevelop on Linux? I was certain that under .Net 3.5 I was able to initialize an array with a variable containing the width of the array. Can anyone confirm that this is isolated? If so, I can report the bug to bugzilla.

    Read the article

  • DefaultIfEmpty doesn't work

    - by Freshblood
    Why is array still null after queried by DefaultIfEmpty ? class Program { static void Main(string[] args) { Program[] array = new Program[5]; Program[] query = array.DefaultIfEmpty(new Program()).ToArray(); foreach (var item in query) { Console.WriteLine(item.ToString()); } Console.ReadKey(); } }

    Read the article

  • switching C compiler causes: Error Initializer cannot be specified for a flexible array member

    - by user1054210
    I am trying to convert our code from one IDE to be used in a different one. The current one uses gcc which allows for this structure to be initialized from a variable array. The new tool does not use gcc gives me an error "Initializer cannot be specified for a flexible array member". So can someone help me understand how to set this up? Should I set up a blank array of variable size and then somewhere assign the #define array as seen below? Here would be an example of the code…(this is current implementation current IDE) In one header file that is Build switchable so we can build this on different hardware platforms we have the following #define #define GPIOS \ /* BANK, PIN, SPD, MODE,… */ GPIOINIT( A, 0, 2, AIN, …) \ GPIOINIT( A, 1, 2, AIN, …) \ GPIOINTINIT(A, 2, 2, AIN, …) \ . . . Then in a different header file that is used in all builds we have PLATFORM_CONFIG_T g_platformConfig = { .name = {PLATFORM_NAME}, (bunch of other stuff), .allGpios = { GPIOS /* here I get the error */ }, }; So I am thinking I can make the error line a variable array and assign to it later in some other way? The problem is the actual array "GPIO" is of different types and pin orders on different designs are different.

    Read the article

  • JAVA - multirow array

    - by user51447
    Here is my situation: a company has x number of employees and x number of machines. When someone is sick, the program have to give the best possible solution of people on the machines. But the employees can't work on every machine. I need a code for making little groups of possible solutions. this is a static example private int[][] arrayCompetenties={{0,0,1,0,1},{1,0,1,0,1},{1,1,0,0,1},{1,1,1,1,1},{0,0,0,0,1}}; = row is for the people and columns are for machines m1 m2 m3 m4 m5 m6 m7 p1 1 1 p2 1 1 1 1 p3 1 1 1 p4 1 1 1 p5 1 1 1 1 p6 1 1 1 1 p7 1 1 1 1 1 1 my question = with what code do i connect all the people to machine in groups (all the posibilities) like: p1 - m1 , p2-m2 , p3 - m3 , p4-m4 , p5 - m5 , p6-m6 p1 - m1 , p2-m3 , p3 - m3 , p4-m4 , p5 - m5 , p6-m6 p1 - m1 , p2-m4 , p3 - m5 , p4-m4 , p5 - m5 , p6-m6 p1 - m1 , p2-m5 , p3 - m3 , p4-m4 , p5 - m5 , p6-m6 p1 - m1 , p2-m2 , p3 - m3 , p4-m4 , p5 - m5 , p6-m6 .... i need a loop buth how? =D thanks!

    Read the article

  • How to partition bits in a bit array with less than linear time

    - by SiLent SoNG
    This is an interview question I faced recently. Given an array of 1 and 0, find a way to partition the bits in place so that 0's are grouped together, and 1's are grouped together. It does not matter whether 1's are ahead of 0's or 0's are ahead of 1's. An example input is 101010101, and output is either 111110000 or 000011111. Solve the problem in less than linear time. Make the problem simpler. The input is an integer array, with each element either 1 or 0. Output is the same integer array with integers partitioned well. To me, this is an easy question if it can be solved in O(N). My approach is to use two pointers, starting from both ends of the array. Increases and decreases each pointer; if it does not point to the correct integer, swap the two. int * start = array; int * end = array + length - 1; while (start < end) { // Assume 0 always at the end if (*end == 0) { --end; continue; } // Assume 1 always at the beginning if (*start == 1) { ++start; continue; } swap(*start, *end); } However, the interview insists there is a sub-linear solution. This makes me thinking hard but still not get an answer. Can anyone help on this interview question?

    Read the article

  • Setting synthesized arrays causing memory leaks using nested arrays

    - by webtoad
    Hello: Why is the following code causing a memory leak in an iPhone App? All of the initted objects below leak, including the arrays, the strings and the numbers. So, I'm thinking it has something to do with the the synthesized array property not releasing the object when I set the property again on the second and subsequent time this piece of code is called. Here is the code: "controller" (below) is my custom view controller class, which I have a reference to, and I am setting with this code snippet: sqlite3_stmt *statement; NSMutableArray *foo_IDs = [[NSMutableArray alloc] init]; NSMutableArray *foo_Names = [[NSMutableArray alloc] init]; NSMutableArray *foo_IDsBySection = [[NSMutableArray alloc] init]; NSMutableArray *foo_NamesBySection = [[NSMutableArray alloc] init]; // Get data: NSString *sql = @"select distinct p.foo_ID, p.foo_Name from foo as p "; if (sqlite3_prepare_v2(...) == SQLITE_OK) { while (sqlite3_step(statement) == SQLITE_ROW) { int p_id; NSString *foo_Name; p_id = sqlite3_column_int(statement, 0); char *str2 = (char *)sqlite3_column_text(statement, 1); foo_Name = [NSString stringWithCString:str2]; [foo_IDs addObject:[NSNumber numberWithInt:p_id]]; [foo_Names addObject:foo_Name]; } sqlite3_finalize(statement); } // Pass the array itself into another array: // (normally there is more than one array in each array) [foo_IDsBySection addObject: foo_IDs]; [foo_NamesBySection addObject: foo_Names]; [foo_IDs release]; [foo_Names release]; // Set some synthesized properties (of type NSArray, nonatomic, // retain) in controller: controller.foo_IDsBySection = foo_IDsBySection; controller.foo_NamesBySection = foo_NamesBySection; [foo_IDsBySection release]; [foo_NamesBySection release]; Thanks for any help!

    Read the article

  • Method in RootViewController not Storing Array

    - by Antonio
    I have an array initialized in my RootViewController and a method that addsObjects to an array. I created a RootViewController object in my SecondViewController. The method runs (outputs a message) but it doesn't add anything to the array, and the array seems empty. Code is below, any suggestions? RootViewController.h #import "RootViewController.h" #import "SecondViewController.h" @implementation RootViewController - (void)viewDidLoad { [super viewDidLoad]; myArray2 = [[NSMutableArray alloc] init]; NSLog(@"View was loaded"); } -(void)addToArray2{ NSLog(@"Array triggered from SecondViewController"); [myArray2 addObject:@"Test"]; [self showArray2]; } -(void)showArray2{ NSLog(@"Array Count: %d", [myArray2 count]); } -(IBAction)switchViews{ SecondViewController *screen = [[SecondViewController alloc] initWithNibName:nil bundle:nil]; screen.modalTransitionStyle = UIModalTransitionStyleCoverVertical; [self presentModalViewController:screen animated:YES]; [screen release]; } SecondViewController.m #import "SecondViewController.h" #import "RootViewController.h" @implementation SecondViewController -(IBAction)addToArray{ RootViewController *object = [[RootViewController alloc] init]; [object addToArray2]; } -(IBAction)switchBack{ [self dismissModalViewControllerAnimated:YES]; } EDIT***** With Matt's code I got the following error: " expected specifier-qualifier-list before 'RootViewController' "

    Read the article

  • PHP Notice: Undefined index when looping array...

    - by Jonathan
    Hi, I'm looping a two-dimensional array like this: if (!empty($aka)) { foreach ($aka as $ak) { if($ak["lang"]=="es") { $sptitle=$ak["title"]; } } } Pretty simple. If the array ($aka) is not empty I loop trough it and when it finds that the "lang" index is equal to "es" I just save the "title" value for that index in $sptitle. The problem is that the array ($aka) contains a lot of information and sometimes there is no "lang" index... and I get this error: Notice: Undefined index: lang. How can I fix this??? This is a extract of the array to help you understand. Notice that [1] doesn't have a [lang] index but [2] does have: [1] =&gt; Array ( [title] =&gt; The Lord of the Rings: The Motion Picture [year] =&gt; [country] =&gt; USA [comment] =&gt; promotional title ) [2] =&gt; Array ( [title] =&gt; Señor de los anillos: La comunidad del anillo, El [year] =&gt; [country] =&gt; Argentina [comment] =&gt; Chile, Mexico, Peru, Spain [lang] =&gt; es ) Thanks!

    Read the article

  • Javascript - cannot make static reference to non-static function ....

    - by Ankur
    I am making a reference to the Javascript function splice() on an array and I get the error: "Cannot make a static reference to the non-static function splice()" What's going on - how is this a static reference, aren't I referencing an instance of an Array class and its method - how is that static? $(document).ready( function() { var queryPreds = new Array(); var queryObjs = new Array(); function remFromQuery(predicate) { for(var i=0; i<arrayName.length;i++ ) { if(queryPreds[i]==predicate) queryPreds.splice(i,1); queryObjs.splice(i,1); } } }

    Read the article

  • How to implement callback methods inside classes (PHP)

    - by sombe
    I need to use a class callback method on an array inside another method (the callback function belongs to the class). class Database { public function escape_string_for_db($string){ return mysql_real_escape_string($string); } public function escape_all_array($array){ return array_filter($array,"$this->escape_string_for_db"); } } Is this the right way to go about that? (I mean, in terms of the second parameter passed to array_filter)

    Read the article

  • How to find every possible combination of an arbitrary number of arrays in PHP

    - by Travis
    I have an arbitrary number of nested arrays in php. For example: Array ( [0] => Array ( [0] => 36 [0] => 2 [0] => 9 ) [1] => Array ( [0] => 95 [1] => 21 [2] => 102 [3] => 38 ) [2] => Array ( [0] => 3 [1] => 5 ) ) I want to find the most efficient way to combine all possible combinations of each of these nested arrays. I'd like to end up with something that looks like this... Array ( [0] => "36,95,3" [1] => "36,95,5" [2] => "36,21,3" [3] => "36,21,5" etc... ) The order the results are combined in is not important. That is to say, there is no difference between "3,95,36", "36,95,3", and "95,36,3". I would like to omit these redundant combinations. Any suggestions on how to go about this would be much appreciated. Thanks in advance,

    Read the article

  • C++ arrays as parameters, EDIT: now includes variable scoping

    - by awshepard
    Alright, I'm guessing this is an easy question, so I'll take the knocks, but I'm not finding what I need on google or SO. I'd like to create an array in one place, and populate it inside a different function. I define a function: void someFunction(double results[]) { for (int i = 0; i<100; ++i) { for (int n = 0; n<16; ++n) //note this iteration limit { results[n] += i * n; } } } That's an approximation to what my code is doing, but regardless, shouldn't be running into any overflow or out of bounds issues or anything. I generate an array: double result[16]; for(int i = 0; i<16; i++) { result[i] = -1; } then I want to pass it to someFunction someFunction(result); When I set breakpoints and step through the code, upon entering someFunction, results is set to the same address as result, and the value there is -1.000000 as expected. However, when I start iterating through the loop, results[n] doesn't seem to resolve to *(results+n) or *(results+n*sizeof(double)), it just seems to resolve to *(results). What I end up with is that instead of populating my result array, I just get one value. What am I doing wrong? EDIT Oh fun, I have a typo: it wasn't void someFunction(double results[]). It was: void someFunction(double result[])... So perhaps this is turning into a scoping question. If my double result[16] array is defined in a main.cpp, and someFunction is defined in a Utils.h file that's included by the main.cpp, does the result variable in someFunction then wreak havoc on the result array in main?

    Read the article

  • Android xml Array returning 0 for getIndexCount()

    - by user1459976
    i'm storing data in an xml array in this fashion <resources> <array name="myarray"> <item> <item>attribute1</item> <item>attribute2</item> <item>and so on</item> </item> <item> <item>attribute1</item> <item>attribute2</item> <item>and so on</item> </item> <item> <item>attribute1</item> <item>attribute2</item> <item>and so on</item> </item> </array> </resources> // in program TypedArray array = getResources().obtainTypedArray(R.array.myarray); when i call array.getIndexCount() in the program it returns 0, what is wrong?

    Read the article

  • XCode Obj-C: Make new NSArray from one key each out of an Array of Dictionaries

    - by user323772
    This actually could be a multipart question. But here's the first part ... I have an array (actually in a plist) of dictionaries. Each dictionary has 3 keys in it: (title), (points), and (description). I am trying to make a NEW array with the values of the key "title" from each dictionary in that first array. Let me explain WHY I am doing this and maybe that will provide a better all around explanation. I am trying to let people pick from a pre-determined list. Heck, if this was a web page it would be very simple since all I really care about are the "points" and the "Title". On a web site I could simply do a drop down combo-box with the "points" being the value and the title being the text for each row. But this is not a web page. So what I am trying to do here is pop out a modal picker when they click the text field. The modal picker shows the alphabetical ordered "titles" from our new array. And whichever one they select, it closes the modal view and assigns that "title" text to the UITextField which cannot be edited by the user. I have some code to get my modal picker to pop out. But I need to feed it an array of just the "titles" of each dictionary in my real array. Thanks in advance (and yes I am a newbie)

    Read the article

  • Any way to define getters for lazy variables in Javascript arrays?

    - by LLer
    I'm trying to add elements to an array that are lazy-evaluated. This means that the value for them will not be calculated or known until they are accessed. This is like a previous question I asked but for objects. What I ended up doing for objects was Object.prototype.lazy = function(var_name, value_function) { this.__defineGetter__(var_name, function() { var saved_value = value_function(); this.__defineGetter__(var_name, function() { return saved_value; }); return saved_value; }); } lazy('exampleField', function() { // the code that returns the value I want }); But I haven't figured out a way to do it for real Arrays. Arrays don't have setters like that. You could push a function to an array, but you'd have to call it as a function for it to return the object you really want. What I'm doing right now is I created an object that I treat as an array. Object.prototype.lazy_push = function(value_function) { if(!this.length) this.length = 0; this.lazy(this.length++, value_function); } So what I want to know is, is there a way to do this while still doing it on an array and not a fake array?

    Read the article

  • PHP: Check if 0?

    - by tarnfeld
    Hi, I am using a class which returns me the value of a particular row and cell of an excel spreadsheet. To build up an array of one column I am counting the rows and then looping through that number with a for() loop and then using the $array[] = $value to set the incrementing array object's value. This works great if none of the values in a cell are 0. The class returns me a number 0 so it's nothing to do with the class, I think it's the way I am looping through the rows and then assigning them to the array... I want to carry through the 0 value because I am creating graphs with the data afterwards, here is the code I have. // Get Rainfall $rainfall = array(); for($i=1;$i<=$count;$i++) { if($data->val($i,2) != 'Rainfall') // Check if not the column title { $rainfall[] = $data->val($i,2); } } For your info $data is the excel spreadsheet object and the method $data->val(row,col) is what returns me the value. In this case I am getting data from column 2. Screenshot of spreadsheet http://cl.ly/1Dmy Thanks! All help is very much appreciated!

    Read the article

  • Can this be done in 1 line? [PHP]

    - by Angelo
    Can this be done in 1 line with PHP? Would be awesome if it could: $out = array("foo","bar"); echo $out[0]; Something such as: echo array("foo","bar")[0]; Unfortunately that's not possible. Would it be possible like this? So I can do this for example in 1 line: echo array(rand(1,100), rand(1000,2000))[rand(0,1)];

    Read the article

< Previous Page | 57 58 59 60 61 62 63 64 65 66 67 68  | Next Page >