Guys,
I’m referring to this tutorial:
It shows 2 methods of creating an array:
[php]
<?php
/* First method to create array. */
$numbers = array( one, two, three, four, five);
foreach( $numbers as $value ) {
echo "Value is $value <br />";
}
/* Second method to create array. */
$numbers[0] = "one";
$numbers[1] = "two";
$numbers[2] = "three";
$numbers[3] = "four";
$numbers[4] = "five";
foreach( $numbers as $value ) {
echo "Value is $value <br />";
}
?>
</body>
</html>
[/php]
On the first method, I just switched the numerical numbers to numbers in words but I get error! It should’ve worked no matter what the values of the arrays are on (note the first method below).
I changed it to:
[php]
<?php
//2 examples On How To Create Numeric Arrays:
?>
<html>
<body>
<?php
/* First method to create array. */
$numbers = array( one, two, three, four, five);
foreach( $numbers as $value ) {
echo "Value is $value <br />";
}
/* Second method to create array. */
$numbers[0] = "one";
$numbers[1] = "two";
$numbers[2] = "three";
$numbers[3] = "four";
$numbers[4] = "five";
foreach( $numbers as $value ) {
echo "Value is $value <br />";
}
?>
</body>
</html>
[/php]
This is the result I get:
**Notice: Use of undefined constant one - assumed 'one' in C:\xampp\htdocs\test\test.php on line 41**
**Notice: Use of undefined constant two - assumed 'two' in C:\xampp\htdocs\test\test.php on line 41**
**Notice: Use of undefined constant three - assumed 'three' in C:\xampp\htdocs\test\test.php on line 41**
**Notice: Use of undefined constant four - assumed 'four' in C:\xampp\htdocs\test\test.php on line 41**
**Notice: Use of undefined constant five - assumed 'five' in C:\xampp\htdocs\test\test.php on line 41**
**Value is one **
**Value is two **
**Value is three **
**Value is four **
**Value is five **
**Value is one **
**Value is two **
**Value is three **
**Value is four **
**Value is five**
My point:
If following works without any errors then the further following too should work:
/* First method to create array. Example, according to tutorial. This sows no errors. */
$numbers = array( 1, 2, 3, 4, 5);
/* First method to create array. Example, according to my editing. This shows errors. */
$numbers = array( one, two, three, four, five);