multidimensional-array

Dynamic array key in while loop

Hi I'm trying to get this working: I have an array that gets "deeper" every loop. I need to add a new array to the deepest "children" key there is. while($row = mysql_fetch_assoc($res)) { array_push($json["children"], array( "id" => "$x", "name" => "S...

Is there a way to get an array out of a multidimensional array in C#?

function(int[] me) { //Whatever } main() { int[,] numbers = new int[3, 2] { {1, 2}, {3, 4}, {5, 6} }; function(numbers[1]); } So here, I'd want to pass int[] {3,4} to the function... but that doesn't work. Is there a way to do that? ...

Creating multi-dimensional array from DB

Hi I really hope someone can help me with this. I'm struggling with it for nearly two days now... I have a DB-table "Device" and a table "Connection". I'm using it to visualize my company's network. To pass the data to the JS-framework I use to visualize the data I need an array like this: Array ( [id] => 1 [name] => TestPC1 ...

How to propagate a current menu item flag upwards in a multidimensional array?

I have a menu being built via a multi-dimensional array. A current item is set by matching its url attribute with the current request. I want this value to bubble up to its parents, but I can't for the life of me get it working - I'm sure I've been close, but it's proving a bit tricky. Here's the array: Array ( [children] => Array ...

Malloc a 3-Dimensional array in C?

Hey all, I'm translating some MATLAB code into C and the script I'm converting makes heavy use of 3D arrays with 10*100*300 complex entries. The size of the array also depends on the sensor's input, ideally the array should be allocated dynamically. So far I've tried two approaches the first being a flat 1D array along the lines of va...

Passing multidimensional array back through access members.

I have a class "foo" that has a multi dimensional array and need to provide a copy of the array through a getArray member. Is there a nice way of doing this when the array is dynamically created so I can not pass the array back a const as the array is always being deleted, recreated etc. I thought about creating a new dynamic array to pa...

Simple question: In numpy how do you make a multidimensional array of arrays?

Right, perhaps I should be using the normal Python lists for this, but here goes: I want a 9 by 4 multidimensional array/matrix (whatever really) that I want to store arrays in. These arrays will be 1-dimensional and of length 4096. So, I want to be able to go something like column = 0 #column to ins...

Multidimensional arrays in Java extends which class?

Hello everyone, I need to know which class multidimensional arrays in Java extends exactly? When we assign Object[] ref=new int[]{1,2,3}; the compiler complains that the objects are of different types. So it seems that one dimensional arrays extend Object; I know that already. But when we assign Object[] ref2=new int[][]{{1,2,3},{...

In PHP5, how do I create a multidimensional array from a database query?

I am creating a class for an application "backbone" and I need this function to query the db, and return a multidimensional to look like this: $myArray = ("name"=>"John", "dob"=>"January 5, 1955"); Of course the data for the array is from a database query. but, "name" and "dob" would be the database column name and "John" and "Januar...

How to print one array of a multidimensional array in Perl?

#!usr/bin/perl @array = (); open(myfile,"sometext.txt"); while(<myfile>) { chomp; push(@array,[split(" ")]); } close(myfile); print @array[0]; Instead of printing the elements of the first array in this multidimensional array, it outputs the hexadecimal(?) pointer reference. If anyone knows how I can print this array, please po...

Performance comparison of array of arrays vs multidimensional arrays

When I was using C++ in college, I was told to use multidimensional arrays (hereby MDA) whenever possible, since it exhibits better memory locality since it's allocated in one big chunk. Array of arrays (AoA), on the other hand, are allocated in multiple smaller chunks, possibly scattered all over the place in the physical memory whereve...

PHP: filtering 2 dimensional array / multidimensional array

hi all, i need help on filtering my 2 dimensional array such as example below: array(29) { [0]=> array(2) { [0]=> string(16) "Andorra La Vella" [1]=> string(2) "AD" } [1]=> array(2) { [0]=> string(16) "Andorra La Vella" [1]=> string(2) "AD" } [2]=> array(2) { [0]=...

How to find every possible combination of an arbitrary number of arrays in PHP

I have an arbitrary number of nested arrays in php. For example: Array ( [0] => Array ( [0] => 36 [0] => 2 [0] => 9 ) [1] => Array ( [0] => 95 [1] => 21 [2] => 102 [3] => 38 ) [2] => Array ( ...

Are the subscripts for three-dimensional arrays strictly defined?

Let's say I declare this: int [a][b][c]; Does a stand for the level/page, b the row and c the column? Or can it be anything I want it to be i.e. a stands for column, b stands for page, and c stands for row (since data is just data and a cube can be abstracted any way)? ...

How to initialize a two-dimensional array in Python?

I'm beginning python and I'm trying to use a two-dimensional list, that I initially fill up with the same variable in every place. I came up with this: def initialize_twodlist(foo): twod_list = [] new = [] for i in range (0, 10): for j in range (0, 10): new.append(foo) twod_list.append(new) ...

print two dimensional array of strings as String

I know how to do toString method for one dimensional arrays of strings, but how to print two dimensional array ? With 1D I do it this way : public String toString() { StringBuffer result = new StringBuffer(); res = this.magnitude; String separator = ""; if (res.length > 0) { result.append(res[0]); for (i...

Multidimensional array with unequal second dimension size using malloc()

Hello, I am playing around with multidimensional array of unequal second dimension size. Lets assume that I need the following data structure: [&ptr0]->[0][1][2][3][4][5][6][7][8][9] [&ptr1]->[0][1][2] [&ptr2]->[0][1][2][3][4] int main() { int *a[3]; int *b; int i; a[0] = (int *)malloc(10 * sizeof(int)); a[1] = (int *)malloc(2...

how to reduce 2d array

I have a 2d array, let's say like this : 2 0 8 9 3 0 -1 20 13 12 17 18 1 2 3 4 2 0 7 9 How to create an array reduced by let's say 2nd row and third column? 2 0 9 13 12 18 1 2 4 2 0 9 ...

How can I extract values out of this array?

Array ( [status] => success [stories] => Array ( [0] => Array ( [name] => John Doe [age] => 23) [1] => Array ( [name] => John Doe_1 [age] => 23) [2] => Array ( [name] => John Doe_2 [age] => 23) ...

Multidimensional array, problem with getting recursive variable output

I’m working on a multi dimensions array but i have a problem Imagine I have a company that can order some furniture’s Fx 5 chair of different type’s width different standard prices different discount (%) and a price after discount now what If a company can choose 3 of the 5 chairs to their design range and add each chair thru as chec...