Questions tagged [arrays]
An array is an ordered linear data structure consisting of a collection of elements (values, variables, or references), each identified by one or more indexes. When asking about specific variants of arrays, use these related tags instead: [vector], [arraylist], [matrix]. When using this tag, in a question that is specific to a programming language, tag the question with the programming language being used.
arrays
31,447
questions
1363
votes
29
answers
2.2m
views
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
I'm running a PHP script and continue to receive errors like:
Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php on line 10
Notice: Undefined index: my_index C:\wamp\www\...
1286
votes
39
answers
281k
views
Reference - What does this error mean in PHP?
What is this?
This is a number of answers about warnings, errors, and notices you might encounter while programming PHP and have no clue how to fix them. This is also a Community Wiki, so everyone is ...
1135
votes
32
answers
1.3m
views
How can I access and process nested objects, arrays, or JSON?
I have a nested data structure containing objects and arrays. How can I extract the information, i.e. access a specific or multiple values (or keys)?
For example:
var data = {
code: 42,
...
361
votes
25
answers
1.0m
views
What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it?
What does ArrayIndexOutOfBoundsException mean and how do I get rid of it?
Here is a code sample that triggers the exception:
String[] names = { "tom", "bob", "harry" };
for (int i = 0; i <= ...
495
votes
11
answers
110k
views
What is array-to-pointer conversion aka. decay?
What is array-to-pointer conversion aka. decay? Is there any relation to array pointers?
462
votes
10
answers
213k
views
Why aren't variable-length arrays part of the C++ standard?
I haven't used C very much in the last few years. When I read this question today I came across some C syntax which I wasn't familiar with.
Apparently in C99 the following syntax is valid:
void foo(...
2080
votes
28
answers
1.1m
views
Why is using "for...in" for array iteration a bad idea?
I've been told not to use for...in with arrays in JavaScript. Why not?
2421
votes
37
answers
3.3m
views
What's the simplest way to print a Java array?
In Java, arrays don't override toString(), so if you try to print one directly, you get the className + '@' + the hex of the hashCode of the array, as defined by Object.toString():
int[] intArray = ...
326
votes
14
answers
96k
views
How can I sort arrays and data in PHP?
This question is intended as a reference for questions about sorting arrays in PHP. It is easy to think that your particular case is unique and worthy of a new question, but most are actually minor ...
2069
votes
58
answers
1.6m
views
How to randomize (shuffle) a JavaScript array?
I have an array like this:
var arr1 = ["a", "b", "c", "d"];
How can I randomize / shuffle it?
4159
votes
61
answers
3.4m
views
Sort array of objects by string property value
I have an array of JavaScript objects:
var objs = [
{ first_nom: 'Laszlo', last_nom: 'Jamf' },
{ first_nom: 'Pig', last_nom: 'Bodine' },
{ first_nom: 'Pirate', last_nom: '...
5722
votes
41
answers
5.4m
views
Loop (for each) over an array in JavaScript
How can I loop through all the entries in an array using JavaScript?
88
votes
6
answers
150k
views
How can I access an array/object?
I have the following array and when I do print_r(array_values($get_user));, I get:
Array (
[0] => 10499478683521864
[1] => 07/22/1983
[2] => [email protected]
...
398
votes
17
answers
552k
views
How to find the size of an array (from a pointer pointing to the first element array)?
First off, here is some code:
int main()
{
int days[] = {1,2,3,4,5};
int *ptr = days;
printf("%u\n", sizeof(days));
printf("%u\n", sizeof(ptr));
return 0;
}
Is there a way to ...
1546
votes
56
answers
1.8m
views
How to compare arrays in JavaScript?
I'd like to compare two arrays... ideally, efficiently. Nothing fancy, just true if they are identical, and false if not. Not surprisingly, the comparison operator doesn't seem to work.
var a1 = [1,2,...