Hi all,
I am trying to make a dynamic Javascript loop and in it I need to define some elements of an array. In that array, they are error labels coded like such:
<form onsubmit="return radio_validate(this, 'Rating[1]', 'Rating[2]')">
So from my PHP array, I want to do a foreach loop, but I need to test for the last element of the array (because I do not want to echo the comma after the last item in the array). I searched this forum and PHP.net and could not find an answer, but I am sure there is a way to do this.
My current code is...
foreach($video as $key => $value) {
echo $value . ' Poor ';
for ($x=1; $x<=5; $x++) {
echo "<input type=\"radio\" value=\"$value\" name=\"Rating$key\"> ";
}
echo ' Very Efficient<br>';
}
But will not work as it stands, because it does not test for the last element in the array and results in an output like...
<form onsubmit="return radio_validate(this,
'Rating0','Rating1','Rating2',)">
Notice the "extra" comma after 'Rating2'. This is why I need to test for the last element in the array, so I can not echo that.
Thanks for the help in advance,
Don