arrays

Matching an array value by key in PHP

I have an array of items: array( [0] => array( 'item_no' => 1 'item_name' => 'foo ) [1] => array( 'item_no' => 2 'item_name' => 'bar' ) ) etc. etc. I am getting another array from a third party source and need to remove items that are not in my first array. array( [0] => array( 'item_no' => 1 ) [1] =...

remove whitespace from each array item rails

I found this code: .each_key {|a| self[a].strip! if self[a].respond_to? :strip! } on this website: http://granth.ca/2006/02/strip-whitespace but I assume that is for a hash, I am trying to do the same with an array. I have tried a few different things, but cannot figure it out. Thank you for any help ...

c++ array to vector issue

Hi, Im trying to copy an array to a vector, however, when the data is copied to the vector its different from that of the original array. int arraySize = 640000; std::vector<unsigned char> vector_buffer; unsigned char buffer[arraySize]; populateArray(&buffer); for(int i = 0; i < arraySize; i++) cout << buffer[i]; // this pri...

How to declare array string in c++

This is very basic but so: I want a string with 4 characteres: "abcd" how must I declare a new string, like that? char *newStr = new char[4]; // or -> char newStr[4]; strcpy(newStr, "abcd"); the null '\0' character must be on the size of the string, so new char[5]? ...

iParameterInspector array manipulation of inputs OR accessing members of an object in an array of Objects

I have an array of objects (with just one element) which is sent to a function (IParameterInspector - but that is not important) , the element is an object with a string and an int. In the function (inspector) i need to access the actual string and integer. How would i do this? so : private object test(string operationName, object[] in...

Automatically expiring variable

How to implement an automatically expiring variable in python? For example, Let the program running For one hour. I want implement an array of 6 variables, each variable in array will be automatically deleted themselves after 10 mins. And after 1 hour, there will be no variable in the array. ...

multidimensional arrays

When dealing with multidimensional arrays is it possible to assign two different variable types to the array... For example you have the array int example[i][j] is it possible for i and j to be two completely different variable types such as int and string? ...

Add to existing array

I have an array of serialized form information (collected using the serialize functionality in jQuery), and would like to add additional information to it. From what I've read it looks like I need to use the push function in Javascript. Unfortunately when I try this I get an error message saying that 'formData.push is not a function' M...

Passing a large array between pages in PHP

Is there any way to pass an array between two pages intact? I am building a huge array, and the building of it uses masses of memmory. I would like to be able to store the array intact and then reaccess it from another page? If I use $x = print_r($array,true); and write it to a file, how could I then rebuild it into an array, or is the...

Surprising pointers

I am surprised to see this code segment print the same address for all the three pointers. int main(int argc,char *argv[]) { int arr[3][3]; printf("%p\n%p\n%p\n",arr,*arr,arr[0]); return 0; } Why this is so ? ...

Efficient array elements un-ordering in Java

Hi people, I just wanted to know what is the best way to un-order the elements in an ordered array in Java, Thanks ...

const C Struct Array within Struct Array

I am attempting to create a const structure in C but can't seem to figure it out. typedef struct sA{ char* fname; char* lname; } A; To use as an Array: A list[] = {{"david","smith"},{"john","smith"}}; However, if I have use a second struct: typedef struct sB{ A inList[]; } B; I want to define a const structure as: B newList...

Sort an array of char in C

I have been struggling to write a simple code to sort an array of char in C and been failing miserably. This is what I have so far: int main() { char line[128]; char word[128]; int i=0; int j; int length; while(fgets(line,sizeof line,stdin) != NULL) { length=0; i=0; while (line[i]!='\0') i++; lengt...

selecting an array key based on partial string

Hello there, I have an array and in that array I have an array key that looks like, show_me_160 this array key may change a little, so sometimes the page may load and the array key maybe show_me_120, I want to now is possible to just string match the array key up until the last _ so that I can check what the value is after the last und...

Whats the fastest way to find a consecutive day list.

i have an array of vacation dates. These are always going to be weekdays. Lets say DateTime[] dates = new DateTime[] {"1/8/2010","1/3/2010","1/6/2010","1/7/2010","1/21/2010"} i now have a single input date. Lets say: DateTime vacationDateToCheck = 1/7/2010; i want to find the vacation set (list of dates) given the set above. In ...

How can I create a two-dimensional array in Perl?

I am currently trying to pass a matrix file that is 32 by 48 to a multi-dimensional array in Perl. I am able to access all of the values but am having issues accessing a specific value. I need to run specific statistics on each of the values, calculate zscore, subtract the mean from each value, penalize specific values et cetera. I tried...

Convert array into csv

Hi, I would like to ask on how to convert array into csv file. this is my array: stdClass Object ( [OrderList_RetrieveByContactResult] => stdClass Object ( [OrderDetails] => stdClass Object ( [entityId] => 1025298 [orderId] => 10952 [...

How to remove all instances of duplicated values from an array

I know there is array_unique function, but I want to remove duplicates. Is there a built-in function or do I have to roll my own. Example input: banna, banna, mango, mango, apple Expected output: apple ...

Trying to pass an array outside the scope into a function for echo'ing.

Hello my fellow programmers, I have a problem (other than not knowing enough) I need to know how to pass an array from outside the scope to then back inside, in a function which then echo's a specific array index. I have trowlled through the net trying to find solutions, asked fellow programmers for help but nothing thus far has worked...

In Java, How do you quicksort an ArrayList of objects in which the sorting field is multiple layers deep?

Basically, I have a Container class called "Employees" which has in it an ArrayList. This ArrayList contains "Employee" objects, which in turn contain "EmployeeData" objects which in turn contain String objects such as "first" or "last" (which are employee names). Here's a diagram of the ArrayList structure: ArrayList[Employee] emps ==...