Tagged Questions
218
votes
5answers
48k 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> ...
274
votes
5answers
168k views
Sort Multi-dimensional Array by Value [duplicate]
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 ...
44
votes
13answers
36k 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 ...
294
votes
20answers
406k 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? ...
25
votes
12answers
34k views
How to “flatten” a multi-dimensional array to simple one in PHP?
It's probably beginner question but I'm going through documentation for longer time already and I can't find any solution. I thought I could use implode for each dimension and then put those strings ...
60
votes
11answers
67k views
in_array() and multidimensional array
I use in_array() to check whether a value exists in an array like below,
$a = array("Mac", "NT", "Irix", "Linux");
if (in_array("Irix", $a))
{
echo "Got Irix";
}
//print_r($a);
but what about ...
48
votes
6answers
77k views
passing 2D array to function
I have a function which I want to take, as a parameter, a 2d array of variable size.
So far I have this:
void myFunction(double** myArray){
myArray[x][y] = 5;
etc...
}
And I have ...
2
votes
3answers
1k views
Sorting a multidimensional array in PHP?
I have this kind of an array
array(5) {
[0]=>
array(5) {
[0]=>
string(7) "jannala"
[1]=>
string(10) "2009-11-16"
[2]=>
string(29) "
<p>Jotain ...
22
votes
3answers
12k 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 ...
8
votes
6answers
12k 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
...
2
votes
2answers
993 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] ...
19
votes
4answers
12k 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 ...
17
votes
9answers
16k views
How do I best handle dynamic multi-dimensional arrays in C/C++?
What is the accepted/most commonly used way to manipulate dynamic (with all dimensions not known until runtime) multi-dimensional arrays in C and/or C++.
I'm trying to find the cleanest way to ...
39
votes
3answers
2k views
Why is numpy's einsum faster than numpy's built in functions?
Lets start with three arrays of dtype=np.double. Timings are performed on a intel CPU using numpy 1.7.1 compiled with icc and linked to intel's mkl. A AMD cpu with numpy 1.6.1 compiled with gcc ...
13
votes
9answers
6k 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';
...
5
votes
5answers
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'] = ...
16
votes
4answers
19k views
Group a multidimensional array by a particular value?
Hopefully, I can explain this correctly...
I have a multidimensional array and am trying to group them according to the value of one the keys.
So, I'm trying to group them by level, but I won't ...
37
votes
4answers
9k views
Why do C# Multidimensional arrays not implement IEnumerable<T>?
I have just noticed that a multidimensional array in C#, does not implement IEnumerable<T>, while it does implement IEnumerable. For single-dimensional arrays, both IEnumerable<T> and ...
3
votes
8answers
7k 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", ...
3
votes
4answers
1k 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] ...
1
vote
2answers
838 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" => ...
20
votes
5answers
2k 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?
14
votes
10answers
10k 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() {
...
47
votes
8answers
46k views
Create two-dimensional arrays and access sub-arrays in Ruby
I wonder if there's a possibility to create a two dimensional array and to quickly access any horizontal or vertical sub array in it?
I believe we can access a horizontal sub array in the following ...
4
votes
3answers
3k 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 = ...
14
votes
5answers
11k views
Pointer address in a C multidimensional array
I'm messing around with multidimensional arrays and pointers. I've been looking at a program that prints out the contents of, and addresses of, a simple array. Here's my array declaration:
int ...
1
vote
1answer
3k views
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
(
...
1
vote
2answers
864 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,
...
20
votes
5answers
26k views
PHP tree structure for categories and sub categories without looping a query
I'm trying to create a list of categories with any number of sub categories, where sub categories can also has their own sub categories.
I have selected all categories from the Mysql db, the cats are ...
39
votes
5answers
52k views
multidimensional array [][] vs [,] [duplicate]
double[][] ServicePoint = new double[10][9]; // <-- give me error (1)
double[,] ServicePoint = new double[10,9]; // <-- ok (2)
What' their different? (1) gives me error, what's the reason?
...
17
votes
4answers
99k 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" => ...
1
vote
5answers
2k 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 = ...
11
votes
4answers
13k views
Implode and Explode Multi dimensional arrays [duplicate]
Are there any functions for recursively exploding and imploding multi-dimensional arrays in PHP?
2
votes
2answers
2k 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 (
...
4
votes
3answers
4k views
Max Array Size in C
I have a program problem for which I would like to declare a 256x256 array in C. Unfortunately, I each time I try to even declare an array of that size (integers) and I run my program, it terminates ...
1
vote
4answers
702 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 ...
25
votes
4answers
14k views
A pointer to 2d array
I have a question about a pointer to 2d array. If an array is something like
int a[2][3];
then, is this a pointer to array a?
int (*p)[3] = a;
If this is correct, I am wondering what does [3] ...
14
votes
8answers
14k 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 ...
8
votes
3answers
948 views
Array to pointer decay and passing multidimensional arrays to functions
I know that an array decays to a pointer, such that if one declared
char things[8];
and then later on used things somewhere else, things is a pointer to the first element in the array.
Also, from ...
7
votes
3answers
15k views
Get the maximum value from an element in a multidimensional array?
I'm trying to select the maximum value for a particular key in a multidimensional array. I'm having trouble "getting to" the key in question...
So, the array (which is much more lengthy than what ...
5
votes
8answers
677 views
Are a, &a, *a, a[0], &a[0] and &a[0][0] identical pointers?
I have the following C program:
#include <stdio.h>
int main(){
int a[2][2] = {1, 2, 3, 4};
printf("a:%p, &a:%p, *a:%p \n", a, &a, *a);
printf("a[0]:%p, &a[0]:%p \n", ...
4
votes
3answers
11k 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 ...
2
votes
5answers
2k views
Walk array recursively and print the path of the walk
Can someone help me with some code or instructions on how to walk recursively an array and when reaching the last element print the full path to it? A simple echo will work because I will adapt the ...
2
votes
4answers
889 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 ...
1
vote
7answers
9k views
How to deep copy an irregular 2D array
How can I deep copy an irregularly shaped 2D array in Java?
Ie.
int[][] nums = {{5},
{9,4},
{1,7,8},
{8,3,2,10}}
I'm unable to use ...
0
votes
1answer
342 views
How to create multi-dimensional array from a list?
I have a list of categories in MySQL with parent ID. How can I create a PHP array from the list.
ID Category Parent_ID
1 Car NULL
2 Education NULL
3 Mathematics 2
4 ...
0
votes
2answers
5k 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 ...
23
votes
5answers
31k views
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
7
votes
3answers
4k 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'),
...
5
votes
5answers
2k views
Get array's key recursively and create underscore seperated string
Right now i got an array which has some sort of information and i need to create a table from it. e.g.
Student{
[Address]{
[StreetAddress] =>"Some Street"
...