Tagged Questions
105
votes
5answers
8k views
How do I use arrays in C++?
C++ inherited arrays from C where they are used virtually everywhere. C++ provides abstractions that are easier to use and less error-prone (std::vector<T> since C++98 and std::array<T, n> ...
76
votes
5answers
43k views
Sort multidimensional Array by Value (2) [closed]
Possible Duplicate:
How do I sort a multidimensional array in php
How can I sort this array by the value of the "order" key? Even though the values are currently sequential, they will not ...
15
votes
6answers
8k views
How to Flatten a Multidimensional Array?
Is it possible, in PHP, to flatten a (bi/multi)dimensional array without using recursion or references?
I'm only interested in the values so the keys can be ignored, I'm thinking in the lines of ...
82
votes
11answers
105k views
How can I create a two dimensional array in JavaScript?
I have been reading online and some places say it isn't possible, some say it is and then give an example and others refute the example, etc.
How do I declare a 2 dimensional array in JavaScript? ...
2
votes
7answers
3k views
sorting 2D array of String in java
I know that this question might have been asked before, but I was not able to find a fit answer. So say I have this array:
String [][] theArray = {{"james", "30.0"},{"joyce", "35.0"},{"frank", ...
5
votes
3answers
4k views
Using numpy to build an array of all combinations of two arrays
I'm trying to run over the parameters space of a 6 parameter function to study it's numerical behavior before trying to do anything complex with it so I'm searching for a efficient way to do this.
My ...
4
votes
6answers
2k views
Sorting multidimensional array in PHP
I am currently creating a sorting method that consists of values from an mysql query.
Here's a brief view of the array:
Array
(
[0] => Array
(
['id'] = ...
2
votes
2answers
266 views
String with array structure to Array
I have string:
Main.Sub.SubOfSub
And some kind of data, may be a string:
SuperData
Also I have an empty array:
$k = array();
How I can transform it all to this array above?
Array
(
[Main] ...
1
vote
2answers
294 views
Nested array. Third level is disappearing
I have that array :
$a = array(
"7" => array(
"id" => 7,
"parent" => 6
),
"6" => array(
"id" => 6,
"parent" => 5
),
"5" => ...
8
votes
9answers
2k views
How to pass a multidimensional array to a function in C and C++
#include<stdio.h>
void print(int *arr[], int s1, int s2) {
int i, j;
for(i = 0; i<s1; i++)
for(j = 0; j<s2; j++)
printf("%d, ", *((arr+i)+j));
}
int main() {
...
4
votes
3answers
5k views
php multi-dimensional array remove duplicate
Not sure if this question is a duplicate in need of removal, but I couldn't find the answer elsewhere so I'll have a go at asking.
I've got a 2d array that looks as follows:
Array
(
[0] => Array
...
8
votes
8answers
3k views
PHP 2D Array output all combinations
I've had this problem bending my mind for a while now (head cold doesn't help either!), basically I have a PHP array which looks like this example:
$array[0][0] = 'apples';
$array[0][1] = 'pears';
...
1
vote
2answers
1k views
Convert flat array to the multi-dimentional
I have an array with tree data (by parent id). I want to convert it to multidimensional array. What is the best way to achieve that? Is there any short function for that?
Source array:
$source = ...
2
votes
2answers
624 views
PHP - Multiple uasort functions breaks sorting
I have a multidimensional array that stores people.
Array (
id93294 => (array (
Name => "Tom Anderson",
Birthday => "03/17/1975"),
id29349 => (array (
...
16
votes
4answers
459 views
May I treat a 2D array as a contiguous 1D array?
Consider the following code:
int a[25][80];
a[0][1234] = 56;
int* p = &a[0][0];
p[1234] = 56;
Does the second line invoke undefined behavior? How about the fourth line?
7
votes
2answers
594 views
Transaprently flatten an array
Reading this question Merge and group by several arrays i got the following idea: when working with multilevel arrays, with possibly repeating keys, it would be practical to have a function that would ...
1
vote
2answers
233 views
Converting an array from one to multi-dimensional based on parent ID values
I've got a one-dimensional array of objects that represent multi-dimensional data:
array(
array(
"id" => 45,
"parent_id" => null
),
array(
"id" => 200,
...
1
vote
4answers
171 views
use strings to access (potentially large) multidimensional arrays
I am having trouble figuring out a way to simply parse a string input and find the correct location within a multidimensional array.
I am hoping for one or two lines to do this, as the solutions I ...
5
votes
3answers
4k views
Implode and Explode Multi dimensional arrays
Are there any functions for recursively exploding and imploding multi-dimensional arrays in PHP?
0
votes
1answer
1k views
PHP search for Key in multidimensional array
I have this:
Array
(
[carx] => Array
(
[no] => 63
)
[cary] => Array
(
[no] => 64
)
)
How can I find the key carx ...
10
votes
3answers
63k views
PHP foreach loop through multidimensional array
I have an array:
$arr_nav = array( array( "id" => "apple",
"url" => "apple.html",
"name" => "My Apple"
),
array( "id" => "orange",
"url" => ...
4
votes
7answers
1k views
malloc in C, but use multi-dimensional array syntax
Is there any way to malloc a large array, but refer to it with 2D syntax? I want something like:
int *memory = (int *)malloc(sizeof(int)*400*200);
int MAGICVAR = ...;
MAGICVAR[20][10] = 3; //sets the ...
6
votes
3answers
1k views
Sort multidimensional array by multiple keys
I'm trying to sort a multidimensional array by multiple keys, and I have no idea where to start. I looked at uasort, but wasn't quite sure how to write a function for what I need.
I need to sort by ...
5
votes
3answers
3k views
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 ...
4
votes
4answers
2k views
PHP -Sanitize values of a array
I have a array, which comes from $_POST[] and can have other arrays in it as values, like:
array(
'title' => 'Title',
'data' => array(
'hdr' => 'Header'
'bdy' ...
1
vote
3answers
3k views
PHP remove duplicate values from multidimensional array
We can use array_unique() for remove duplicate entry from a single multidimensional array in php.Is it possible to use with multidimensional array? It is not working for me!
Here's what the array ...
1
vote
3answers
611 views
PHP Walk through multidimensional array while preserving keys
I've got a multidimensional array of which I can't know the depth. The array could for example look like this:
$array = array(
1 => array(
5 => array(
3 => ...
1
vote
2answers
198 views
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 ...
1
vote
4answers
391 views
How to sort a multidimensional array by a certain key?
This should be really simple, but what is the way to go on this.
I want to sort an multidimensional array by a key, like this:
Array (
[0] => Array
(
[iid] => 1
[invitee] ...
0
votes
1answer
387 views
Sorting an array into a multidimensional array based on “parent_id”
I'm storing an infinitely nested directory structure in mysql by assigning a "parent_album_id" to each "album" (unless it's at the top level, in which case it does not have a parent_album_id).
I ...
7
votes
9answers
1k views
Is int *array[32] a pointer to an array of 32 ints, or an array of 32 pointers to int? Does it matter?
If I write
int *columns[32];
am I defining an array with 32 pointers to ints?
Or is it a pointer to an array of 32 ints?
How do I differentiate between the two? Is there a difference?
1
vote
5answers
687 views
In C/C++, is char* arrayName[][] a pointer to a pointer to a pointer OR a pointer to a pointer?
I understood multi-dimensional arrays as pointers to pointers, but perhaps I am wrong?
For example, I though:
char * var = char var[]
char ** var = char* var[] or char var[][]
char *** var = ...
8
votes
3answers
933 views
Are there any jquery features to query multi-dimensional arrays in a similar fashion to the DOM?
What the question says...
Does jQuery have any methods that will allow you to query a mult-dimensional array of objects in a similar fashion as it does with the DOM.
So for instance, get me a list ...
6
votes
4answers
3k views
Java: Multi-dimensional array vs. One-dimensional
For example:
a) int [x][y][z]
vs
b) int[x*y*z]
Initially thought i'd go with a) for simplicity
I know that Java doesn't store arrays linearly in memory like C does. But what implications does this ...
2
votes
4answers
213 views
Turning multidimensional array into one-dimensional array
I've been banging my head on this one for a while now.
I have this multidimensional array:
Array
(
[0] => Array
(
[0] => foo
[1] => bar
[2] ...
8
votes
6answers
6k views
Malloc a 3-Dimensional array in C?
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 ...
6
votes
2answers
4k views
Php multi-dimensional array from mysql result
I have a mysql table that looks like this:
id | uid | title | description | parent
1 | 1 | Portraits | desc. | photostream
2 | 1 | Abstract | descr. | photostream
and I am ...
4
votes
2answers
2k views
PHP convert nested array to single array while concatenating keys?
Here is an example array:
$foo = array(
'employer' => array(
'name' => 'Foobar Inc',
'phone' => '555-555-5555'
),
...
2
votes
5answers
386 views
Flatten multidimensional array concatenating keys [closed]
Possible Duplicate:
PHP convert nested array to single array while concatenating keys?
Get array's key recursively and create underscore seperated string
Please, read the whole ...
2
votes
3answers
882 views
find max() of specific multidimensional array value in php
See array for example: here
Basically, I want to find the max() for array[]['time'] in that array. I can figure it out if I loop through it, but I was hoping there was a more elegant solution.
1
vote
4answers
538 views
PHP - Mutidimensional array diff
i would like to ask for your help since I'm having difficulty resolving this matter. I had created a function to facilitate on array diff but it does not suffice to my needs. Thanks and more power!
...
0
votes
2answers
387 views
Initial array in function to aggregate multi-dimensional array
I have a table with arrays of integer.
I want to create an aggregate function that will return a 2-dimensional array with all the rows together. It then gets passed to plr to do some maths on it.
I ...
6
votes
7answers
1k views
3D array C++ using int [] operator
I'm new to C/C++ and I've been cracking my head but still got no idea how to make an "structure" like this
It's supposed to be a 3D dynamic array using pointers.
I started like this, but got stuck ...
4
votes
3answers
328 views
Transform flat array into a hierarchical, multi-dimensional array
I have a standard array with key-value pairs - and I want to use the keys to transform it into a multi-dimensional array. The difficulty seems to be that I need to loop recursively the unknown number ...
2
votes
3answers
94 views
Sorting a php array of arrays by custom order
I have an array of arrays:
Array (
[0] => Array (
[id] = 7867867,
[title] = 'Some Title'),
[1] => Array (
[id] = 3452342,
[title] = 'Some Title'),
...
2
votes
6answers
158 views
Find similar rows in 3 two-dimensional arrays
What is the best approach to solve the following problem in Java?
There are 3 two-dimensional arrays that have equal number of rows and columns:
Array1:
[1]: {1, 2, 3}
[2]: {2, 2, 4}
[3]: {1, 1, 1}
...
2
votes
2answers
121 views
reliably convert string containing PHP array info to array
suppose I have the string
$str = "array(1,3,4),array(array(4,5,6)),'this is a comma , inside a string',array('asdf' => 'lalal')";
and I try to explode this into an array by comma so that the ...
2
votes
3answers
290 views
In javascript how can I dynamically get a nested property of an object
var arr = { foo : 1, bar: { baz : 2 }, bee : 3 }
function getter(variable) {
return arr[variable];
}
If I want 'foo' vs 'bee' I can just do arr[variable] - that's easy, and the function does ...
2
votes
3answers
1k views
Pass 2d array to function in C?
I know it's simple, but I can't seem to make this work.
My function is like so:
int GefMain(int array[][5])
{
//do stuff
return 1;
}
In my main:
int GefMain(int array[][5]);
...
2
votes
2answers
390 views
how to sort a multidemensional array by an inner key
i have this enormous array that i am pulling from an API for BattleField Bad Company 2, and the soldier stats can be pulled as a multi dimensional array with an inner array for each soldier, however ...