418,170 questions
3
votes
2
answers
2k
views
.NET Multi Dimensional Array Printing
Let's say I have a .NET Array of n number of dimensions. I would like to foreach through the elements and print out something like:
[0, 0, 0] = 2
[0, 0, 1] = 32
And so on. I could write a loop ...
21
votes
7
answers
61k
views
Iterating over a two dimensional array
Is there an easy way to iterate over an associative array of this structure in PHP:
The array $searches has a numbered index, with between 4 and 5 associative parts. So I not only need to iterate ...
34
votes
9
answers
28k
views
How would you implement a hashtable in language x? [closed]
The point of this question is to collect a list of examples of hashtable implementations using arrays in different languages. It would also be nice if someone could throw in a pretty detailed overview ...
12
votes
10
answers
9k
views
How can I merge PHP arrays?
I have two arrays of animals (for example).
$array = array(
array(
'id' => 1,
'name' => 'Cat',
),
array(
'id' => 2,
'name' => 'Mouse',
)
);
...
6
votes
9
answers
2k
views
Classes vs 2D arrays
Which is better to use in PHP, a 2D array or a class? I've included an example of what I mean by this.
// Using a class
class someClass
{
public $name;
public $height;
public $weight;
...
4
votes
10
answers
1k
views
How Does One Sum Dimensions of an Array Specified at Run-Time?
I am working on a function to establish the entropy of a distribution. It uses a copula, if any are familiar with that. I need to sum up the values in the array based on which dimensions are "...
4
votes
3
answers
5k
views
How do I compare two arrays of DataRow objects in PowerShell?
I have two arrays of System.Data.DataRow objects which I want to compare.
The rows have two columns A and B. Column A is a key and I want to find out which rows have had their B column changed and ...
40
votes
8
answers
81k
views
How to split a byte array
I have a byte array in memory, read from a file. I would like to split the byte array at a certain point (index) without having to just create a new byte array and copy each byte at a time, ...
1
vote
5
answers
5k
views
How can I sort an array of double pointers based on the values they point to?
I am trying to build a function in C/C++ to sort an array and replace each value with its "score" or rank. It takes in a double pointer array to an array of ints, and sorts the double pointers based ...
52
votes
8
answers
20k
views
Can placement new for arrays be used in a portable way?
Is it possible to actually make use of placement new in portable code when using it for arrays?
It appears that the pointer you get back from new[] is not always the same as the address you pass in (...
6
votes
7
answers
17k
views
How does one rank an array (sort) by value? *With a twist*
I would like to sort an array in ascending order using C/C++. The outcome is an array containing element indexes. Each index is corespondent to the element location in the sorted array.
Example
Input: ...
12
votes
6
answers
685
views
Replacement for for... if array iteration
I love list comprehensions in Python, because they concisely represent a transformation of a list.
However, in other languages, I frequently find myself writing something along the lines of:
foreach ...
50
votes
9
answers
20k
views
PHP: Access Array Value on the Fly [duplicate]
In php, I often need to map a variable using an array ... but I can not seem to be able to do this in a one liner. c.f. example:
// the following results in an error:
echo array('a','b','c')[$key];
/...
247
votes
29
answers
441k
views
How do I remove duplicates from a C# array?
I have been working with a string[] array in C# that gets returned from a function call. I could possibly cast to a Generic collection, but I was wondering if there was a better way to do it, possibly ...
177
votes
11
answers
246k
views
How do I remove duplicate items from an array in Perl?
I have an array in Perl:
my @my_array = ("one","two","three","two","three");
How do I remove the duplicates from the array?
28
votes
6
answers
15k
views
Can you force either a scalar or array ref to be an array in Perl?
I have a perl variable $results that gets returned from a service. The value is supposed to be an array, and $results should be an array reference. However, when the array has only one item in it, $...
42
votes
6
answers
89k
views
What is the best way to iterate through an array in Classic Asp VBScript?
In the code below
For i = LBound(arr) To UBound(arr)
What is the point in asking using LBound? Surely that is always 0.
58
votes
8
answers
16k
views
Using 'in' to match an attribute of Python objects in an array
I don't remember whether I was dreaming or not but I seem to recall there being a function which allowed something like,
foo in iter_attr(array of python objects, attribute name)
I've looked over ...
79
votes
9
answers
10k
views
Create a tag cloud by wrapping array values in h1 through h6 tags based on a mapping array of weights
I have the following arrays:
$artist = ["the roots", "michael jackson", "billy idol", "more", "and more", "and_YET_MORE"];
$count = [5, 3, 9,...
97
votes
8
answers
12k
views
How to unload a ByteArray using Actionscript 3?
How do I forcefully unload a ByteArray from memory using ActionScript 3?
I have tried the following:
// First non-working solution
byteArray.length = 0;
byteArray = new ByteArray();
// Second non-...