arrays

Restricting the size of an array when passed to a function

Is there anyway to restrict the size of an array when passed as an argument to a function? I mean is something like this possible? /*following will lead to compile time error */ template<typename T, size_t n>=20> // or template<typename T,size_t n<=20> void func(T (&a)[n]) { // do something with a } I want the size of my array t...

PHP - Merge duplicate array keys in a multidimensional array

I have a multidimensional array called $songs, which outputs the following: Array ( [0] => Array ( [Michael Jackson] => Thriller ) [1] => Array ( [Michael Jackson] => Rock With You ) [2] => Array ( [Teddy Pendergrass] => Love TKO ) [3]...

.NET Reflection and an array.

I'm trying to get the value of a property that is a single dimensional array via reflection I tried something like this: (try catches removed for clarity) string[] fieldOrder; PropertyInfo fieldOrderColumn; fieldOrderColumn = targetType.GetProperty("OrderArray"); if (fieldOrderColumn == null) throw new Exception(targetType.Name +...

Java: Are there some tools out there which are able to refactor X[][] to List<List<X>>?

Hello, everyone! I have to refactor an existing project, which is not that small. It contains a lot of arrays declarations and accesses: (X is not a generic type, it's just a placeholder). declarations: X[] and X[][], access: someArray[i] and someArray[i][j]. I have to rewrite everything to use generic Lists: declaration: List<X> and L...

Associative array lookup in memory

Its just a question out of curiosity. Suppose we have an associative array A. How is A["hello"] actually evaluated , as in how does system map to a memory location using index "hello"? ...

PHP case-insensitive in_array function

Is it possible to do case-insensitive comparison when using the in_array function? So with a source array like this: $a= array( 'one', 'two', 'three', 'four' ); The following lookups would all return true: in_array('one', $a); in_array('two', $a); in_array('ONE', $a); in_array('fOUr', $a); What function or set of functions wou...

Method for key-value pair similar to explode in php?

Is there an already existing function in PHP for creating an associative array from a delimited string? If not, what would be the most effective means of doing so? I am looking at PayPal's new NVP API, where requests and responses have the following format: method=blah&name=joe&id=joeuser&age=33&stuff=junk I can use explode() to get ...

Is there a function that will recursively traverse the values of an array?

I have an array that may have some null or blank values in it. Is there a PHP function that I can use to traverse this array to simply find out if there is a value anywhere? For example: [0]=> [1]=> [2]=> test I'd like to test against the total number of values present, if any. count() won't work because this is only a portion of thi...

very basic objective-c question

Hi all, I wrote a simple program to understand how objective-c works. This program is the i-ching, an ancient divination based on six lines response, calculated after launching three coins for six times, and then build an hexagram which is the reponse. I am stuck at this, that I am sure has simple solution. This is how I defined the li...

c++ use of ptr as array base

On page 42 of Effective C++, a pointer is used as an array name ala AirPlane *newBlock = ... newBlock[i].next=0; I've not been aware that this is legal. Is this part of the c++ standard? Is it common practice? ...

How to get user from multilevel array?

I have the following array from DB. Now I want to get shin in [user] => shin. How can I get it with PHP? Number in [29] => Array could be any number. Thanks in advance. Array ( [29] => Array ( [0] => stdClass Object ( [day] => 29 [eventContent] => scho...

How to read complex PHP arrays?

I've been working with ProjectPier, and found arrays like the following. How do I read this architecture with PHP? ApplicationLog Object ( [is_new:DataObject:private] => [is_deleted:DataObject:private] => [is_loaded:DataObject:private] => 1 [column_values:DataObject:private] => Array ( [id] => 24 [taken_by_id] => 1...

How to optimize this method with System.arraycopy?

What's a more efficient way of writing this method: static Foo[][] copy2D(Foo[][] in) { Foo[][] ret = new Foo[in.length][in[0].length]; for(int i = 0;i < in.length;i++) { for(int j = 0;j < in[0].length;j++) { ret[i][j] = in[i][j].clone(); } } return ret; } ...

C: creating array of strings from delimited source string

What would be an efficient way of converting a delimited string into an array of strings in C (not C++)? For example, I might have: char *input = "valgrind --leak-check=yes --track-origins=yes ./a.out" The source string will always have only a single space as the delimiter. And I would like a malloc'ed array of malloc'ed strings char...

PHP: Split string into array, like explode with no delimiter...

I have a string such as: "0123456789" and need to split EACH character into an array. I for the hell of it tried: explode('', '123545789'); But it gave me the obvious: Warning: No delimiter defined in explode) .. How would I come across this? I can't see any method off hand, especially just a function ...

Dynamic array allocation in C++ question

I have a struct of type Duplicate I have a variable of type int called stringSize, it has a value of 5 I am creating a dynamic array: Duplicate *duplicates; duplicates = new Duplicate[stringSize - 1]; Later I delete[] duplicates; I'm getting one member in that array only? I've verified that stringSize - 1 = 4 with a debug walk throug...

multidimension array

Hi, I want to create a multidimensional array based on a string. the string has value $string="1/2/3" and i want to assign $array[1][2][3]=somethimg actually the index of the array are described inside the $string The $string has not same depth. For example may be $string="1/2 OR $string="1/2/3/4/5 OR $string="1/2/3/5/7/8/9/9/6 so...

PHP array as variable name

How to send an indexes name for php array vairable. the array is $array = array('Somthing'=>array('More'=>array('id'=> 34))); and now I want to display this thing but with a variable name I don't know how to explain so I write what I want to have. $index_name = '[Something][More][id]'; $array{$index_name}; Is it possible in any...

set values to elements of an array in a function

Hi, In a bash script, I would like to put the following code that assigns values to each element of several arrays into a function for (( i=0 ; i < ${#themes[@]} ; i+=1 )); do c_bit_mins[i]=-5 c_bit_maxs[i]=15 gamma_bit_mins[i]=-15 gamma_bit_maxs[i]=3 done i.e. something like function set_values() { for (( i=0 ; i ...

Getting string from NSDictionary nested in a plist file

Hi, I am trying to get a string out of a plist file that contains a nested dictionary. This is the plist: <dict> <key>DataPoints</key> <array> <dict> <key>source</key> <string>BloomBerg</string> <key>date</key> <date>2010-01-31T14:54:13Z</date> <key>value</key> ...