arrays

Sorting an array in ascending order without losing the index Objective-C

Hello all, I have an array for instance, Array { 3.0 at Index 0 2.0 at Index 1 3.5 at Index 2 1.0 at Index 4 } I would like to get sort it in ascending order without losing the index in the first place, like this, Array { 1.0 at Index 4 2.0 at Index 1 3.0 at Index 0 3.5 at Index 2 } When I so...

Custom array sorting based on instance properties

I'm trying to perform a usort on an array inside an instance of a class. But the sort is dependent on the properties of said instance. Code (which doesn't work): class foo { private $array; private $key; private $dir; function sort() { usort($this->array, array("foo", "orderArray")); } function orderArray($a, $b) { ...

Reorder a multidimensional array?

I have the following array, I need to reorder it by average rating descending. Here is a snippet. Any idea how I would go about doing this? Thanks Array ( [0] => Array ( [id] => 3 [name] => [rating] => 0 ) [1] => Array ( [id] => 2 [name] => ...

Issues adding search to iPhone app

Hi, Basically I'm trying to add a search function to my iPhone app, but I'm not having much luck at the moment. I've downloaded the Apple provided Table Search app, and have copied across the code to mine. It builds OK, but here's the problem. Unlike the Apple example, all my data is stored in an array, that is accessed by calling [ciPa...

Pass array of data to jQuery function

Here's the story... I have a jQuery function that does something, this function is referenced very regularly. One of the input parameters is an array, this array data is hard coded and thus I want to pass the data like this: (this is how I would do it using PHP) myFunction(Array("url"=>"abc.com","example"=>"hello_world")); Instead of ...

I need some help with either my SQL or my PHP I do not know which...

Hello I am creating a CMS and some of the functionality of it that the images that are within the content are managable. I currently trying to display a table that shows the the content title and then the associated images, ideally I would like a layout similar to this, Content Title Image 1 Image 2 Image 3 Content Title 2...

How do I move an element from an array to another array in javascript?

My code is like var shapes1 = [ r.image("node.gif",190, 100, 47, 45)]; var shapes2 =[]; for (var i = 0, ii = shapes1.length; i < ii; i++) { shapes1[i].mousedown(function(e){ var temp=this.clone(); shapes1.push(temp); //now I want to remove "this" from shapes1 //and put it into shape2 //HOW??...

How do I combine two arrays in PHP based on a common key?

Hi, I'm trying to join two associative arrays together based on an entry_id key. Both arrays come from individual database resources, the first stores entry titles, the second stores entry authors, the key=>value pairs are as follows: array ( 'entry_id' => 1, 'title' => 'Test Entry' ) array ( 'entry_id' => 1, 'author...

Download multiple files from an array C#

Hi everyone, I have an array of file names which I want to download. The array is currently contained in a string[] and it is working inside of a BackgroundWorker. What I want to do is use that array to download files and output the result into a progress bar which will tell me how long I have left for completion. Is there a way I ca...

How to add an element to an array without a modification of the old array or creation a new one?

I have the following construction: for (String playerName: players). I would like to make a loop over all players plus one more special player. But I do not want to modify the players array by adding a new element to it. So, what can I do? Can I replace players in the for (String playerName: players) by something containing all element...

C++, array of objects without <vector>

Hello I want to create in C++ an array of Objects without using STL. How can I do this? How could I create array of Object2, which has no argumentless constructor (default constructor)? ...

dot length in java - finding its definition

In which class is the length field defined in Java (e.g. for array length)? Will I be able to see it defined say in Object class? EDIT : Why was this field so designed(any thing related with security or memory efficiency)? ...

Fast serarch of 2 dimensional array

I need a method of quickly searching a large 2 dimensional array. I extract the array from Excel, so 1 dimension represents the rows and the second the columns. I wish to obtain a list of the rows where the columns match certain criteria. I need to know the row number (or index of the array). For example, if I extract a range from excel...

Java Array Comparison

Working within Java, let's say I have two objects that, thanks to obj.getClass().isArray(), I know are both arrays. Let's further say that I want to compare those two arrays to each other -- possibly by using Arrays.equals. Is there a graceful way to do this without resorting to a big exhaustive if/else tree to figure out which flavor ...

Sorting a string array in C++ no matter of 'A' or 'a' and with å, ä ö?

How do you sort an array of strings in C++ that will make this happen in this order: mr Anka Mr broWn mr Ceaser mR donK mr ålish Mr Ätt mr önD //following not the way to get that order regardeless upper or lowercase and å, ä, ö //in forloop... string handle; point1 = array1[j].find_first_of(' '); string forename1(array1[j].subst...

Evaluating for loops in python, containing an array with an embedded for loop

I was looking at the following code in python: for ob in [ob for ob in context.scene.objects if ob.is_visible()]: pass Obviously, it's a for each loop, saying for each object in foo array. However, I'm having a bit of trouble reading the array. If it just had: [for ob in context.scene.objects if ob.is_visible()] that would ma...

PHP array and foreach help

Hello, I need some help with an array and a foreach loop, I have an array that is data returned from a database, basically it is a list of titles and images associated with it, it looks a little like this, Array ( [0] => Array ( [contentImageId] => 28 [contentImageName] => yellow.png ...

Unknown error in the memory in C

I have a 2D dynamic array. I enter a line of 0's after line which has a biggest number: void InsertZero(int **a, int pos){ int i, j; a = (int**)realloc(a, n * sizeof(*a)); a[n-1] = (int*)calloc(n, sizeof(**a)); d = 0; for(i = n-1; i > pos; i--){ for(j = 0; j < n; j++){ a[i][j] = a[i-1][j]; ...

Can't make an array in C#

I'm trying to make a dynamic array in C# but I get an annoying error message. Here's my code: private void Form1_Load(object sender, EventArgs e) { int[] dataArray; Random random = new Random(); for (int i = 0; i < random.Next(1, 10); i++) { dataArray[i] = random.Next(1, 1000); ...

Getting duplicate key values in array

For some reason when trying to populate an array I am not getting the desired result. In the first part I create an array of arrays, the key of each has a name such as "Biology Education". But when I then populate that same array it doesn't for some reason use the same array element but a new one. So part 1 results in an array with 13 ...