multidimensional-array

How do I count the number of each unique array inside a multidimentional array? PHP

Hi, I'd like to build a simple shopping cart using arrays. I need to display each unique item in the shopping cart aswell as the quantity of each item along side. My initial cart array might look like this: $cart= array( array(2003,100,"Table") ,array(2003,100,"Table") ,array(2003,100,"Table") ,array...

C Program: square brackets when printing 2D character array

Hello, I am having a confusing issue -- for me at least, this may be very simple and I am missing something. I am trying to initialize a 2D array of variable size, The array is a part of a struct. I am having no issue allocating memory for the array but when I try to assign characters to the array, or print them I receive unexpected resu...

C#: Is it possible to position a 2darray in a certain position in another 2darray without iterating through it?

Is it possible to position a 2d array in a certain position in another 2d array without iterating through it? public double[,] array2D; array2D = new double[7,7]; public void fill1D(double[,] values) { Array2D = values; //Values holds a 5x5 array that i wan't to place from 1,1 in array2D } Thanks ...

Turning 2 arrays into a two-dimensional array in java

Hi I am trying to take two arrays and turn them into one 2 dimensional array. However, I keep getting an error: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2 at test5.sum(test5.java:12) at test5.main(test5.java:38) Here is my code: public class test5 { int [][] final23; public int [][] sum(int [] x, ...

Taking N number of arrays and turning it into a multidimensional array with N rows JAVA

I am trying to write code that will turn N arrays into a multidimensional array with N rows. I currently have a code that can turn 2 arrays into a multidimensional array with 2 rows. However, I am unsure how to modify it in order to make this code take N arrays. Additionally my code currently can only take arrays of the same size. Howev...

most effecient way to order an array by sub elements?

I have a multidimensional array. $array[0] = array(1, 8, 2); $array[1] = array(5, 6, 15); $array[2] = array(-8, 2, 1025); I am wondering what the most efficient way to order the parent array by a particular property of it's sub array. For example, I want to put them in ascending order of $sub_array[1], so the parent array would be...

Taking 2 dimensional array and outputting 1 dimensional array in JAVA

I am trying to take a two-dimensional array and run it through a series of calculations in order to transform it into a one-dimensional array. However, when I run my program I keep getting this long error Exception in thread "main" java.lang.Error: Unresolved compilation problems: Duplicate local variable raw_advisor Syntax er...

How to get the length of dynamically allocated two dimensional arrays in C

The question is how to get the length of dynamically allocated 2D Arrays in C? I thought the code below should get the number of rows, but it doesn't. char** lines; /* memory allocation and data manipulation */ int length; //the number of rows length = sizeof(lines)/sizeof(char*); Any thoughts on this? ...

problem with variable assignment to arrays using structs in c

So I'm trying to multiply matrices in c. However when I try to multiply the numbers in the two arrays, and put them in an answer array its always zero. heres the code for the method, thanks. My matrix struct: typedef struct matrix { int r; int c; double **mat; } *matrix_t; My matrix multiplying method: matrix_t mat_mult(matrix_t...

natsort multidemsional array

Hello I have an multidimensional array like this: array ([0] => array ([id] => 1 [name] => john doe [title] => Mr [days] => 10) [1] => array ([id] => 2 [name] => Joe Smith [title] => Dr [days] => 22) [2] => array ([id] => 3 [name] => John Jones [title] => Mr [days] => 3)) I need to sort the inner arrays so that the data is returne...

How do I sort a PHP array by an element nested inside?

I have an array like the following: Array ( [0] => Array ( 'name' => "Friday" 'weight' => 6 ) [1] => Array ( 'name' => "Monday" 'weight' => 2 ) ) I would like to grab the last values in that array (the 'weight'), and use that to sort the main arra...

Remove "columns" from the subarrays of a two dimensional array

I have a simple, two dimensional array like this: Array ( [0] => Array ( [0] => abc [1] => 123 [2] => aaaaa ) [1] => Array ( [0] => def [1] => 456 [2] => ddddd ) [...

How to dynamically set array keys in php

I have some logic that is being used to sort data but depending on the user input the data is grouped differently. Right now I have five different functions that contain the same logic but different groupings. Is there a way to combine these functions and dynamically set a value that will group properly. Within the function these assi...

Perl: Iterating through this funky array?

I'm trying to iterate over a 2D array that is structured in this specific way. Whether or not this is a good way to structure the array is another question - I still need to be able to iterate over it (if it is possible). @row1 = ( "Current Scan", "Last Month"); @row2 = ( "240", "0"); @row3 = ( "226", "209"); @row4 = ( "215", "207"); ...

How to manually initialize a collection of RECORDs in PL/SQL?

Hi, guys. Here's a simple sample two-dimensional array in PL/SQL, which is working perfectly. declare type a is table of number; type b is table of a; arr b := b(a(1, 2), a(3, 4)); begin for i in arr.first .. arr.last loop for j in arr(i).first .. arr(i).last loop dbms_output.put_line(arr(i) (j)); end loop; end ...

Calculating an array of values in C# (Formula convert from Excel)

Hi all, I'm currently building a semi-complicated calculator which is basically a conversion from an Excel spreadsheet I've been provided. I've nailed most of it but there's a part in the Excel spreadsheet where multiple calculations occur between 6 rows and 7 columns, but the issue is that the calculations happen in no particular orde...

C++ Returning multidimension array from function

How do I return a multidimensional array hidden in a private field? class Myclass { private: int myarray[5][5]; public: int **get_array(); }; ........ int **get_array() { return grid; } cannot convert 'int ()[5][5]' to 'int*' in return test.cpp /Polky/src line 73 C/C++ Problem ...

How can I use 3-dimensional data as a class property?

It's been a long time since I worked with C++, but I have a class that uses 3-dimensional data and I can't figure out how I can make this work. I need the sizes of the dimensions to be defined in the constructor. I tried this in the header: class CImage { public: float values[][][]; ... } and this in the constructor: CImage::CIma...

Simplify looping through an array which could be flat or multidimensional

Often, I will have an array holding a set of values each of which I need to process. Sometimes, the array will only hold a single set, in which case each value needs to be put through the process. Other times, the array will hold many sets, in which case each value will be an array and each value of those arrays will need to be processed...

Multi Array Sort PHP

I'm having some problems wrapping my head around how to do this. I have an array in PHP array(131) { ["BLANF "]=> array(3) { ["line_3"]=> string(4) "3.92" ["line_1"]=> string(1) "6" ["line_2"]=> string(2) "14" } ["BLOOH "]=> array(3) { ["lin...