All Questions

799
votes
23answers
1168165 views

PHP: "Notice: Undefined variable", "Notice: Undefined index", and "Notice: Undefined offset"

I am running a PHP script, and keep getting 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\...
535
votes
16answers
289817 views

Access / 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, it...
143
votes
13answers
370244 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[] name = {"tom", "dick", "harry"}; for(int i = 0; i<=name.leng...
1375
votes
22answers
612774 views

Why is using &quot;for...in&quot; with array iteration a bad idea?

A PHP Error was encountered

Severity: Notice

Message: Undefined index: body

Filename: views/Tagged_view.php

Line Number: 87

Backtrace:

File: /home/admin/web/allinonescript.com/public_html/application/views/Tagged_view.php
Line: 87
Function: _error_handler

File: /home/admin/web/allinonescript.com/public_html/application/controllers/Questions.php
Line: 158
Function: view

File: /home/admin/web/allinonescript.com/public_html/index.php
Line: 297
Function: require_once

226
votes
7answers
40955 views

How can I sort arrays and data in PHP?

Due to the enormous and ever repeating amount of "How do I sort my unique snowflake of an array?" questions, this is a reference collection of basic sorting methods in PHP. Please close any questio...
1291
votes
24answers
1421275 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 weird output including the memory location: int[] intArray = new int[] {1, 2, 3, 4, 5}; System.out.println(intA...
406
votes
5answers
107810 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>...
29
votes
4answers
12698 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@saya.com ...
717
votes
35answers
399429 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?
-6
votes
2answers
26559 views

How to avoid ArrayIndexOutOfBoundsException or IndexOutOfBoundsException?

If your question is I am getting a java.lang.ArrayIndexOutOfBoundsException in my code and I do not understand why it is happening. What does it mean and how can I avoid it? This is meant to be th...

Previous Next