multidimensional-array

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]...

What's wrong with my multidimensional - array declaration? C#

private int[, ,] table = new int[4 , 5 , 5]{ {{0,6,2,6,4},{2,2,4,2,8},{4,4,8,4,6},{6,6,2,6,4},{8,8,6,8,2}}, {{0,2,8,8,4},{2,4,6,6,8},{4,8,2,2,6},{6,2,8,8,4},{8,6,4,4,2}}, {{0,4,2,4,4},{2,8,4,8,8},{4,6,8,6,6},{6,4,2,4,4},{8,2,6,2,2}}, {{0,8,8,2,4},{2,6,6,4,8},{4,2,2,8,6},{6,8,8,2,4},{8,4,4,6,2}} }; I want this table: k|...

How to initialize 3D array in C++

How do you initialize a 3d array in C++ int min[1][1][1] = {100, { 100, {100}}}; //this is not the way ...

A little problem in handling 2-D arrays with class

class linklist4x4 { private: struct node4x4 { double data[4][4]; node4x4 *link; }*p; public: linklist4x4(); void append( double* num ); void add_as_first( double* num ); void addafter( int c, double* num ); //void del( double* num ); void display(); int count(); double*...

How can I use a std::valarray to store/manipulate a contiguous 2D array?

How can I use a std::valarray to store/manipulate a 2D array? I'd like to see an example of a 2D array with elements accessed by row/column indices. Something like this pseudo code: matrix(i,j) = 42; An example of how to initialize such an array would also be nice. N.B.: I'm already aware of Boost.MultiArray, Boost.uBlas, and Blitz++...

C++ How to use and pass a 3-dimensional char array?

I'm trying to build a char array for storing the return value of a function. In the following function the data is stored in ***valv. How to build a extern variable to access the data? int credis_lrange(REDIS rhnd, const char *key, int start, int end, char ***valv) { int rc; if ((rc = cr_sendfandreceive(rhnd, ...

How to Get the Direct Access Index for NSDictionary of NSDictionary

Here's the code: NSMutableDictionary *circuit_step = [NSMutableDictionary dictionary]; NSMutableDictionary *step_info = [NSMutableDictionary dictionary]; [step_info setObject: @"search" forKey: @"search-type"]; [step_info setObject: @"small" forKey: @"search-format"]; [step_info setObject: @"winter" forKey: @"...

Are the x,y and row, col attributes of a two-dimensional array backwards?

if I think of the x,y coordinate plane x,y is the common notation for an ordered pair, but if I use a two-dime array I have myArray[row][col] and row is the y and col is the x. Is that backwards or am I just thinking about it wrong? I was thinking it would look like myArray[x][y] but that's wrong if I want real rows and columns (like i...

How to create a list inside the another list?

I would like to create a list inside another list. How can I do this? And how do I retrieve values from the list which is inside another list? ...

Multidimensional array iteration

Say you have the following array: $nodes = array( "parent node", "parent node", array( "child node", "child node", array( "grand child node", "grand child node"))); How would you go about transforming it to an XML string so that it looks like: <node> <node>parent node</n...

PHP's array_merge_recursive behaviour on integer keys

Evening all, Can someone suggest an approach for recursively merging arrays, in the same way as PHP's array_merge_recursive() function does, except that integer keys are treated the same as string keys? (its important for the process that the keys remain parse-able as integers) For example: $a = array( 'a' => array(1) ); $b = arr...

dynamical two dimension array according to input

Hi, I need to get an input N from the user and generate a N*N matrix. How can I declare the matrix? Generally, the size of the array and matrix should be fixed at the declaration, right? What about vector<vector<int>> ? I never use this before so I need suggestion from veteran. ...

C / C++ How to copy a multidimensional char array without nested loops?

I'm looking for a smart way to copy a multidimensional char array to a new destination. I want to duplicate the char array because I want to edit the content without changing the source array. I could build nested loops to copy every char by hand but I hope there is a better way. Update: I don't have the size of the 2. level dimension...

Addressing a single dimensional pointer array with two dimensions

I have the following homework question: Consider the following declarations and answer the question. char strarr1[10][32]; char *strarr2[10]; Are strarr1[3][4] and strarr2[3][4] both legal references? I tried compiling the code with gcc to test it. I was fairly sure that the second reference would throw an error, but it didn't. This ...

Marshaling a C++ two-dimensional fixed length char array as a structure member

I am trying to call an unmanaged C++ function, that has a structure as an input parameter. The structure is defined in the header file like this: struct MyStruct { int siOrder; char aaszNames[6][25]; int siId[6]; int siTones[6]; }; I tried to declare the managed struct as following: [StructLayoutAttribute(Layo...

Recursively merge multidimensional arrays, hashes and symbols

I need a chunk of Ruby code to combine an array of contents like such: [{:dim_location=>[{:dim_city=>:dim_state}]}, :dim_marital_status, {:dim_location=>[:dim_zip, :dim_business]}] into: [{:dim_location => [:dim_business, {:dim_city=>:dim_state}, :dim_zip]}, :dim_marital_status] It needs to support an arbitrary level of depth, ...

php transforming a specific string into array values

hi, i get this response from the server: OK: 0; Sent queued message ID: e3674786a1c5f7a1 SMSGlobalMsgID:6162865783958235 OK: 0; Sent queued message ID: 9589936487b8d0a1 SMSGlobalMsgID:6141138716371692 and so on... This is just one long string with NO carriage return i copied it exactly as received. please note, initial OK can be a...

Multidimensional JavaScript Array to PHP Array

I have been trying to figure this out for awhile. I have a multidimensional array in JavaScript that is 12 columns wide and an unknown number of rows like so /* [ [userID (int), name, username, email, password, other 1, other 2, other 3, other 4, other 5, other 6, admin(int)], [userID (int), name, username, email, password, othe...

php merging two arrays into one

hi, I have two arrays that need to be merged together and trying to figure out the correct way of doing it. this is the first array Array ( [IndividualOutmsg] => Array ( [0] => Array ( [user_id] => 3 [number] => 414566765 ...

PHP - lookup array contents with dot syntax

Does anybody see anything wrong with the following function? (Edit: no, I don't think anything is wrong, I am just double-checking since this will be inserted into a very common code path.) function getNestedVar(&$context, $name) { if (strstr($name, '.') === FALSE) { return $context[$name]; } else { $pieces = exp...