PHP Parse error: parse error, unexpected '[', expecting ')' in G:\\...\\test_array.php on line 47
In the sample code below, test1 and test2 function properly but test3 fails with the above error. The reason I want to use an array is I need to cycle through 14 to 20 parameters passed to the function.
Any help will be appreciated (either with the array or an alternate method to cycle through the parameters in a for loop).
Thanks,
Steve
Code: Select all
<html>
<head>
<title>PHP Test Array in a function</title>
</head>
<body>
<h1>PHP Test Array in a function</h1>
<?php
// TEST 1
// Assign data into a numeric array and output to the screen.
echo "Start of test 1<br />";
$sch[1] = "Sched one";
$sch[2] = "Sched two";
$sch[3] = "Sched three";
$sch[4] = "Sched four";
for ($ctr=1; $ctr<=3; $ctr++)
{
echo "Counter $ctr $sch[$ctr]<br />";
}
echo "End of test 1<br /><br />";
// TEST 2
// Use a function to assign data into variables and then move the data from variables into a numeric array.
function putSchedMat($sch1, $sch2, $sch3, $sch4) {
echo "Start of test 2<br />";
$sch[1] = $sch1;
$sch[2] = $sch2;
$sch[3] = $sch3;
$sch[4] = $sch4;
for ($ctr=1; $ctr<=3; $ctr++)
{
echo "Counter $ctr $sch[$ctr]<br />";
}
echo "End of test 2<br /><br />";
}
// TEST 3
// Use a function to assign data into a numeric array.
function putSchedMat2($sch[1], $sch[2], $sch[3], $sch[4]) {
echo "Start of test 3<br />";
for ($ctr=1; $ctr<=3; $ctr++)
{
echo "Counter $ctr $sch[$ctr]<br />";
}
echo "End of test 3<br /><br />";
}
// Call the putSchedMat function.
putSchedMat("This is one", "This is two", "This is three", "This is four");
// Call the putSchedMat2 function.
//putSchedMat2("This is first", "This is second", "This is third", "This is fourth");
?>
<!--[Thu Mar 26 09:52:12 2009] [error] [client 127.0.0.1] PHP Parse error: parse error, unexpected '[', expecting ')' in G:\\...\\test_array.php on line 47-->
</body>
</html>