arrays

Problem with sorting jagged array.

good morning. i have a jagged array declared like int[][][] tmpA = new int[INT_WORKING_SIZE * 2][][]; I trying to sort this array with this code: Array.Sort(tmpA, 0, INT_WORKING_SIZE*2, new MyArrayComparer()); and my class: public int Compare(object x,object y) { if (x == null || y == null) return 0; ...

Ruby model with an array as an attribute

Hello, I am currently trying t implement a model to simplify graphical chart creation. However, one of the attributes must be an array of attributes. For example: "Chart_Series" has a "name" which would be a string and a data field which would be separated by dates which is an array of arrays [[Date1, Value1],[Date2,Value2],[Date3,Value...

Accesing hash keys and attributes from the view

Hello, in an attempt to create a model with an array as an atribute, i ended up creating an array of hashes like so: data1 = {} data1[:name] = "Virtual Memory" data1[:data] = @jobs.total_virtual_memory data2 = {} data2[:name] = "Memory" data2[:data] = @jobs.total_memory @data = [] @data << data1 @data...

CakePHP: how to access $this->set(array('fruit' => 'orange', 'vegetable' => 'kale')); in controller

I'm new to CakePHP and I'm looking at some code I've downloaded that has a function that looks like this: $this->set(array('fruit' => 'orange', 'vegetable' => 'kale')); In the code, the array variables are accessed in another controller function using this method: $varsSet = $this->viewVars; echo $varsSet['vegetable']; What I'd lik...

How does assigning a variable into an array work when the array item is changed

Hi Do you know... Why does the original string remain unchanged in example 1 and the original instance not get nulled in example 2, when the string property of an object instance is changed in example 3? class A { public string property = "class a"; } static void Main(string[] args) { //Example1 string var ...

Visual Foxpro Array [] or ( )

Dear all, In a Visual Foxpro application one of the users get an error (the rest doesn't). And i believe its because arrays are used in the form of arr(number) instead of arr[number] . Does anyone know what causes this strange behavior at a single user? Thanks! ...

confusion in scanf() with & operator

why do we need to put a & operator in scanf() for storing values in an integer array and not while storing a string in a char array? i.e int a[5]; for(i=0;i<5;i++) scanf("%d",&a[i]); but char s[5]; scanf("%s",s); ? we need to pass in the address of the place we store the value,since array is a pointer to first element so in the case wi...

Problem merging/sorting arrays in PHP

I have 3 arrays like so, that can contain an infinite number of items: Weight Array ( [0] => 20 [1] => 250 [2] => 400 ) Price Array ( [0] => 1.20 [1] => 6.00 [2] => 9.50 ) Courier Array ( [0] => DHL [1] => DHL [2] => UPS ) I'd like to merge them and sort them like so: Array ( [0] => 20 [1] => 1.20 [2] => D...

C# - Any clever way to get an int array from an object collection?

How can I create an easy helper method to get an int array from a collection of objects? The idea would be have a method which receive a collection of "User" class: public class User { public int UserId {get;set;} public string UserName {get;set;} } And filter this collection to get an int array of unique UserIds. List<int...

java: what is this: [Ljava.lang.Object; ?

I get this when I call toString on an object I received from a function call. I know the type of the object is encoded in this string, but I don't know how to read it. What is this type of encoding called? ...

C style char arrays - How many bytes do we store?

char firstName[32]; I understand that each char occupies 1 byte in memory. So does the above occupy 32 bytes of memory? Am I missing a pointer that takes up memory too or is this just 32 bytes? ...

Prototype: Array is an Object and not array?

I've been coding javascript like this: var Foo = { something: function() { }, someValue: 0, someArray: [], someObject: {}, anotherFunction: function (id) { this.someArray.push(id); // works - adds value to array someArray }, removeSomething: function(id) { this.someArray.without(id); //...

Java object creation

Im writing a program that creates an array of classes that run separately. I want to create an array of 500 containing a big class. Whenever i write the loop to create it, it stops at about 30 or so... is there a limit on java or bugging in my program? ...

How can I simplify this array?

I have this array: Array ( [0] => Array ( [tag_id] => 1 ) [2] => Array ( [tag_id] => 3 ) [22] => Array ( [tag_id] => 44 ) [23] => Array ( [tag_id] => 45 ) [25] => Array ( [tag_id] =>...

Java Object and array memory location

I'm writing an array-backed hashtable in Java, where the type of key and value are Object; no other guarantee. The easiest way for me code-wise is to create an object to hold them: public class Pair { public Object key; public Object value; } And then create an array public Pair[] storage = new Pair[8]; But how does the j...

How to search for largest value in array, and return associated key in PHP

I'd like to be able to return the number 15 in this case: Array ( [420315] => 1 [21714] => 1 [20] => 1 [1] => 1 [18] => 1 [241] => 2 [15] => 5 [1038401] => 1 [114] => 1 [293641] => 1 [387] => 1 [232] => 1 [11368] => 1 [9225] => 1 [100] => 1 [9254] => 1 [15326] => 1 [9246] => 1 [97] => 1 [9241] => 1 [14242] => 1 [9456] => 1 [366] => ...

One liner to limit Array of Words to less than N number of characters in Ruby?

What's the simplest way to limit an array of words such that the resulting array, when the words are joined, is less than 40 characters? Something that acts like this: words = ["ruby", "rails", "jquery", "javascript", "html"] words.join.length #=> 29 words.join(", ").length #=> 37 words = ["ruby", "rails", "jquery", "javascript", "html...

How can I force PHP to use strings for array keys?

I've come across an old app that uses an id to name type array, for example... array(1) { [280]=> string(3) "abc" } Now I need to reorder these, and a var_dump() would make it appear that that isn't going to happen whilst the keys are integers. If I add an a to every index, var_dump() will show double quotes around the key, my gu...

vector with constant size

I am looking for a C++ data type similar to std::vector but without the overhead related to dynamic resizing. The size of the container will remain constant over its lifetime. I considered using boost::array, however, that is not appropriate because it requires the size of the array to be known at compile time, which is not the case in m...

How to implode 2 dimensional array into square brackets

Hi guys, I would like to output my php array into this format: [1991, 6.5], [1992, 4], [1993, 5.9] PHP array: while ($row = mysqli_fetch_array($result)) { $metals[] = array('year' => $row['year'], 'metal' => $row['metal']; } I have seen some examples of implode function but I couldn't find any that could matc...