arrays

How to count string length of a domain list and group them by length?

I have a list of domain names, for example: domain1.com domain2.com domainxxx2.com dom.com from that list I want to get: length 7 [2] length 10 [1] length 3 [1] I know how to split the tld and count each domain length, but dont know how to group and count those with the same length. I would like to do it on PHP. ...

PHP Array remove items if missing key

I have the following array format: Array ( [0] => stdClass Object ( [tid] => 3 [children] => Array () ) [1] => stdClass Object ( [tid] => 15 ) [2] => stdClass Object ( [tid] => 12 [children] => Array () ) [3] => st...

How to release the elements of an NSArray, loaded by arrayWithContentsOfURL ?

I am too dumb to know the answer to this one - does anyone know the answer definitively? NSMutableArray *happyDictionaryEntries; @property (nonatomic, retain) NSMutableArray *happyDictionaryEntries; -(void) getStuffFromServer { .. self.happyDictionaryEntries = [NSMutableArray arrayWithContentsOfURL:[NSURL URLWithString:aUrl]]; } ...

Filling an evenly distributed matrix of arrays with PHP

I have an array of objects, containing lists of times. I have to stick this in a Matrix-alike array, in order to put it in a table. This is a part of my earlier SO question on how to build calendar tables $node->sessions = array( 1286452800, // '2010-10-07 14:00:00' 1286460000, // '2010-10-07 16:00:00' ); $node->title = 'Foo'; $node...

Itterating through a PHP array and inserting another array without overwriting

Hi, I am looping through an array, and for each value, I need to insert another array containing a few items. The below code inserts the array fine: foreach($events as $Key => $val): $schedule[$Key] = array( array('event_id' => 'test', 'start_date_time' => 'test', ...

How to get String array from returned XML-RPC object?

I am using Apache java XML-RPC latest version. The code for sending the array in Server is the following: LinkedList<String> messages = new LinkedList<String>(); public String[] getMessages() { System.out.println("Sent messages"); return messages.toArray(new String[messages.size()]); } To receive in the client I have tried s...

Java ArrayList.remove() not decrementing the Size of the ArrayList.

I have an ArrayList to store some data, but whenever I remove an item from the list, the size does not decrease, even when I call ArrayList.trimToSize(). This is causing me nullPointerExceptions. How can I remove a single item from an ArrayList and have the list's size() shrink accordingly? EDIT: All right, here's the code. Here's a bi...

How do I get a reference to a single dimension of a Multidemensional Array in C#?

I've come across a problem where I'd like to create an Array table. That is a 2 dimensional array where the number of rows and columns are known at runtime before the table needs to be created. The number of columns is the same for all rows. Once the array is created I'd like to operate on just 1 dimension of that array. Perhaps pass...

Find all possible row-wise sums in a 2D array

Ideally I'm looking for a c# solution, but any help on the algorithm will do. I have a 2-dimension array (x,y). The max columns (max x) varies between 2 and 10 but can be determined before the array is actually populated. Max rows (y) is fixed at 5, but each column can have a varying number of values, something like: 1 2 3 4 5 6 7.....

How to get a XML element into an array in JSP

I have a simple XML file, such as: <shop> <row num="1"> <shelf1>Fruit</shelf1> <shelf2>Milk</shelf2> </row> <row num="2"> <shelf1>Pens</shelf1> <shelf2>Paper</shelf2> </row> </shop> And I'd like to put shelf1, shelf2, shelf3 and shelf4 into an array. Any ideas on where to start? I'm us...

Why do I only get first element in Javascript array passed from Silverlight?

I'm attempting to pass out an array of strings from a Silverlight application to a Javascript function. However I only seem to get the first element of the array, rather than the whole array. I've reproduced it with the simple code below: Silverlight: string[] Names = new string[5]; Names[0] = "Test1"; Names[1] = "Test2"; Names[2...

Convert 2D array of integers to bitmap in Java

I have a 2D array of integers in Java. I want to take this and output a bitmap image file where the red value of each pixel is the corresponding value in the array (blue and green values are 0). Does anyone know how to do this? Thanks. ...

PHP - Search for variable in array()

If I had this code: $result = 1; $square = array( "00" => -1, "0" => 0, "1" => 1, ); And wanted to know whether $result is equal to ANY of the array VALUES of $square (-1, 0 or 1). I´m am guessing there should be a function that compares a variable to all the array´s values and returs TRUE or FALSE accordingly. If there isn´t suc...

Source code for java array

Where can i find the source code for java arrays? Example: double[] arr=new double[20]; All array's with any dimension implements Cloneable and Serializable interface.I searched the source code but couldn't find the code for this.Any help would be great. ...

Initialization of a pointer array

Hi all, I'm facing a problem initializing an array with pointers to members of a structure. The structure members have to be accessed through a structure pointer. The reason for this is we initialize the pointer at runtime to a memory mapped address location. The following code snippet is an example of the problem; #include <stdio.h> ...

How do I remove the longest prefix that appears in an array?

I have two arrays, search and target. I want to find the longest sequence of elements of search that starts from the beginning of search and which also appears in the same consecutive order in target. Then I want to return a copy of target with those elements removed. Here are some examples: search = [4, "apple", 6, "turnip"] target = ...

PHP Array sorting using child nodes?

Ok I have the following array: Array ( [0] => Array ( [id] => 6 [name] => This Course [time] => 1288082700 [description] => blah blah . [link] => http://this.com/?g=5 [course] => 22 ) [1] => Array ( [id] => 2 [name] => Workshop [time] => 1287561600 ...

C# difference between arr[0]++ and ++arr[0]

In C#, is there a difference between the code (all in one statement, not part of a larger one) arr[0]++; and ++arr[0]; I fully understand, that in C / C++ / Objective-C, that this would not do the same thing, first case would get the value at arr's 0th index and increment that value by one, while the second one, increases the pointer va...

PHP sort multidimensional array with primary & secondary keys

How do you sort a multidimensional array by primary and secondary key? For example, assuming the following array: $result = array(); $result[0]["prio"] = 1; $result[0]["date"] = '2010-02-28'; $result[0]["post"] = "February's thoughts"; $result[1]["prio"] = 0; $result[1]["date"] = '2010-04-20'; $result[1]["post"] = "April's thoughts"; ...

Building query string links

I'm building a filters section for my search page and I was wondering what is the best way to go about doing the query strings. My problem is that these links function a lot like checkboxes, so some, all or none can be on. I'd have to loop through each of about 30 or so links, removing or adding that specific link's value depending on it...