All Questions

794
votes
23answers
1165529 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\...
7664
votes
88answers
1140492 views

How do JavaScript closures work?

How would you explain JavaScript closures to someone with a knowledge of the concepts they consist of (for example functions, variables and the like), but does not understand closures themselves? I h...
1541
votes
22answers
401256 views

What is the scope of variables in JavaScript?

What is the scope of variables in javascript? Do they have the same scope inside as opposed to outside a function? Or does it even matter? Also, where are the variables stored if they are defined glob...
168
votes
11answers
386102 views

Non-static variable cannot be referenced from a static context

I've written this test code: class MyProgram { int count = 0; public static void main(String[] args) { System.out.println(count); } } But it gives the following error: Main...
197
votes
6answers
70010 views

Using a variable for a key in a JavaScript object literal

Why does the following work? <something>.stop().animate( { 'top' : 10 }, 10 ); Whereas this doesn't work: var thetop = 'top'; <something>.stop().animate( { thetop : 10 }, 10 );...
109
votes
9answers
15194 views

Using i and j as variables in Matlab

i and j are very popular variable names (see e.g., this question and this one). For example, in loops: for i=1:10, % do something... end As indices into matrix: mat( i, j ) = 4; Why shoul...
94
votes
12answers
343032 views

How to pass JavaScript variables to PHP?

I want to pass JavaScript variables to PHP using a hidden input in a form. But I can't get the value of $_POST['hidden1'] into $salarieid. Is there something wrong? Here is the code: <script ...
67
votes
20answers
283756 views

How to combine two strings together in PHP?

I don't actually know how to describe what I wanted but I'll show you: For example: $data1 = "the color is"; $data2 = "red"; What should I do (or process) so $result is the combination of $data1 a...
66
votes
7answers
43494 views

"Variable" variables in Javascript?

I know it's possible in PHP to have "variable" variables. For example $x = "variable"; $$x = "hello, world!"; echo $variable; // displays "hello, world!" Is this possible in javascript? How would...
63
votes
7answers
102331 views

Assigning variables with dynamic names in Java

I'd like to assign a set of variables in java as follows: int n1,n2,n3; for(int i=1;i<4;i++) { n<i> = 5; } How can I achieve this in Java?

Previous Next