arrays

ASP.net c# magical array issue

Hello, I'm encountering an interesting issue with the following code. productObject is a custom object that contains a number of product-related variables including a 'VendorLocationId'. Given these items in a listbox: "Town A" value:1 "Town B" value:2 Also given: both items are selected within the listbox. 1 productObjectArray[]...

iPhone SDK: Loading an NSArray from Documents

Hello there, I'm saving an array I use into Documents and when the app loads it puts the array into a UITableView instantly. This loads fine and has all the correct data, but when you try and scroll the UITableView a little bit the whole app crashes... When I refresh with a new set of NSArray from the web it loads fine and scrolls perf...

Transposing multidimensional arrays in PHP

How would you flip 90 degrees (transpose) a multidimensional array in PHP? For example: // Start with this array $foo = array( 'a' => array( 1 => 'a1', 2 => 'a2', 3 => 'a3' ), 'b' => array( 1 => 'b1', 2 => 'b2', 3 => 'b3' ), 'c' => array( 1 => 'c1', 2 => 'c2',...

How to copy a row of values from a 2D array into a 1D array?

We have the following object int [,] oGridCells; which is only used with a fixed first index int iIndex = 5; for (int iLoop = 0; iLoop < iUpperBound; iLoop++) { //Get the value from the 2D array iValue = oGridCells[iIndex, iLoop]; //Do something with iValue } Is there a way in .NET to convert the values at a fixed first inde...

sorting array element using javascript

i need program in which you enter words via the keyboard or file and then they come out sorted by length using javascript ...

Array of pointers to multidimensional arrays

Hi, i have some bidimensional arrays like: int shape1[3][5] = {1,0,0, 1,0,0, 1,0,0, 1,0,0, 1,0,0}; int shape2[3][5] = {0,0,0, 0,0,0, 0,1,1, 1,1,0, 0,1,0}; and so on. How can i make an array of pointers to those? I tried the following, but they don't work (warning: initializat...

PHP - Delete Item from Hash Table (array) using array_filter

Hi In PHP, I know there is no official way to delete items once they have been put into an array. But there must be a "best-method" solution to my problem. I believe this may lie in the array_filter function. Essentially, I have a shopping cart object that stores items in a hashtable. Imagine you can only ever buy one of any item at a ...

What's the most efficient way of filtering an array based on the contents of another array?

Say I have two arrays, items and removeItems and I wanted any values found in removeItems to be removed from items. The brute force mechanism would probably be: var animals = ["cow","dog","frog","cat","whale","salmon","zebra","tuna"]; var nonMammals = ["salmon","frog","tuna","spider"]; var mammals = []; var isMammal; for(var i=0;i<ani...

Are there any practical limitations to only using std::string instead of char arrays and std::vector/list instead of arrays in c++?

I use vectors, lists, strings and wstrings obsessively in my code. Are there any catch 22s involved that should make me more interested in using arrays from time to time, chars and wchars instead? Basically, if working in an environment which supports the standard template library is there any case using the primitive types is actually ...

C array address confusion

Say we have the following code: int main(){ int a[3]={1,2,3}; printf(" E: 0x%x\n", a); printf(" &E[2]: 0x%x\n", &a[2]); printf("&E[2]-E: 0x%x\n", &a[2] - a); return 1; } When compiled and run the results are follows: E: 0xbf8231f8 &E[2]: 0xbf823200 &E[2]-E: 0x2 I understand the result of &E[2] whic...

Trouble passing value array into an Object array

I am trying to pass an array of values into an array of a table object so that I can write them to the database. My database looks like this -> tblCaseNotes CaseNoteID | PersonId | etc, etc tblCaseNotesContactType rowguid | CaseNoteID | ContactTypeID tblMaintItems itemID | CategoryID The itemID from the Maint table is what is being w...

Ruby: How do I join elements of an array together with a prefix?

I have an array like so: ["marblecake", "also", "the", 1337] I would like to get back a string which contains each element of the array prefixed by some specified string, then joined together by another specified string. For example, ["marblecake", "also", "the", 1337].join_with_prefix("%", "__") should result in # => %marblecake_...

Preferred method to store PHP arrays (json_encode vs serialize)

I need to store a multi-dimensional associative array of data in a flat file for caching purposes. I might occasionally come across the need to convert it to JSON for use in my web app but the vast majority of the time I will be using the array directly in PHP. Would it be more efficient to store the array as JSON or as a PHP serialized...

How do I create an array of namespaces?

How can I create an array of namespaces? And because it seems like a long shot, if this is impossible, is there something similar to a namespace that can be made into an array? The namespace, if it helps, contains these variables: const int maxx=// depends on the particular namespace // I need an array to go through eac...

Why does wrapping an Excel array formula in a SUM not produce the sum of the contents in this case?

Clever People, In Excel, it appears that wrapping an array formula in a SUM does not produce the sum of the contents of the array in all cases. (That is, it appears to me; clearly, I could well be confused.) This came up when trying to write the equivalent of an inner join in Excel. For reasons involving Excel for Mac, I'm doing this w...

Ruby: How do I use symbols to represent things in an array?

I have an array of arrays that looks like this: fruits_and_calories = [ ["apple", 100], ["banana", 200], ["kumquat", 225], ["orange", 90] ] I also have a method I want to invoke on each element of the array: fruits_and_calories.each do |f| eat(f[0], f[1]) I'd really like to be able to say something like: fruits_and_calorie...

sorting a ruby array of objects by an attribute that could be nil

Hi All, I have an array of objects that I need to sort by a position attribute that could be an integer or nil, and I need the objects that have the nil position to be at the end of the array. Now, I can force the position to return some value rather than nil so that the array.sort doesn't fail, but if I use 0 as this default, then it p...

Java: Check whether an array is a subset of another

How can I easily check to see if one ArrayList object is contained as a subset of another? ...

How to call an array in a function? PHP

Global scope allows you to use a variable in a function that was defined outside the function. eg $a=1; function $test(){ echo $a; } //outputs 1 but why is it that if I define a variable with an array I cannot use it the same way? $test = array( 0=>'zero', 1=>'one', 2=>'two', 3=>'three', ); function doesntWork($something){ echo ...

Sort Array of MultiDiminsional Arrays on More Than One "Column" (Key) With Specified Sort Options

I'm looking to be able to sort an array of multi-dimensional arrays on more than one column. To further complicate it I'd like to be able to set specific sort options per key/column. I have what is similar the result of a DB query, but doesn't actually come from one, therefore the need to sort it in PHP rather than SQL. Array ( [0] ...