English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I am going through a few tutorials for php and I had to complicate one of the examples by adding a for..loop and I can't figure out why it won't work. Can someone figure it out?

$names = array("Peter", "Quagmire", "Joe");

$namesCount = count($names);

for($i=0; $i<$namesCount; $i+=1)
{
echo $names[i] . " ";
}

?>

ERROR MESSAGE:
PHP Notice: Use of undefined constant i - assumed 'i' in C:\Program Files\PHP\kevin1.php on line 195
PHP Notice: Undefined index: i in C:\Program Files\PHP\kevin1.php on line 1

2007-07-06 01:17:25 · 4 answers · asked by Anonymous in Computers & Internet Programming & Design

PHP Notice: Use of undefined constant i - assumed 'i' in C:\Program Files\PHP\kevin1.php on line 195
PHP Notice: Undefined index: i in C:\Program Files\PHP\kevin1.php on line 195
PHP Notice: Use of undefined constant i - assumed 'i' in C:\Program Files\PHP\kevin1.php on line 195
PHP Notice: Undefined index: i in C:\Program Files\PHP\kevin1.php on line 195
PHP Notice: Use of undefined constant i - assumed 'i' in C:\Program Files\PHP\kevin1.php on line 195
PHP Notice: Undefined index: i in C:\Program Files\PHP\ke

2007-07-06 01:18:15 · update #1

Thanks AnalProgrammer and JACOVKSS2! You were both correct. I am not used to this php language yet. I am more used to VB .NET and ASP .NET. Thanks again!

2007-07-06 01:43:00 · update #2

4 answers

Your echo command is wrong.
It should be
echo $names[$i] . " ";

2007-07-06 01:24:42 · answer #1 · answered by AnalProgrammer 7 · 2 0

there are various concepts you would be able to take. First, you would be able to repeatedly substitute the difficulty you're attempting to freshen up. What assumptions would desire to desire to you're making that would make the difficulty much less complicated? as without postpone as you freshen up that, you would be waiting to desire to confirm why that assumption made it much less complicated, and notice in case you would be able to get rid of it. additionally, learn the techniques of determination subject concerns. The extra advantageous subject concerns you recognize the thank you to freshen up, the less complicated it is to freshen up subject concerns you haven't any longer seen. as quickly as you're authorized, communicate with others, and communicate diverse concepts to the respond. mutually as listening to a various guy or female's answer, hit upon out what's incorrect with their answer. Why does it fail? oftentimes, reading the thank you to freshen up an argument demands understand-how why a answer would perhaps be damaging. With assembly language, there are various times constructs that are lacking (e.g., a on a similar time as loop). which you will think of of of the respond in C or Java and attempt to translate it to assembly. finally, write down each and every of the concepts you have, sturdy and undesirable, and write out why this concept isn't so sturdy or why it is sturdy. you will discover that writing subject concerns out forces you to think of of out loud, and oftentimes that facilitates you manage your concepts. sturdy success.

2016-12-10 03:40:33 · answer #2 · answered by Anonymous · 0 0

AnalProgrammer beat me to it: there's a $ sign missing before i in your echo line.

It helps to be anal in your programming!

2007-07-06 01:30:29 · answer #3 · answered by Anonymous · 1 0

Try making the last part of your loop "$i++" instead of "$i+=1"

2007-07-06 01:22:13 · answer #4 · answered by DanW 3 · 0 1

fedest.com, questions and answers