I am trying to use a FOREACH loop in PHP to output different messages depending on the position of the value in the array. My code is below:
$qtyValidFiles = count($validFiles);
$tick = 0;
foreach($validFiles AS $validItem)
{
if($tick = 0)
{
echo"'#$validItem,";
}
elseif($tick < $qtyValidFiles -1 && $tick != 0)
{
echo"#$validItem,";
}
elseif($tick = $qtyValidFiles -1)
{
echo"#$validItem'";
}
}; $tick++;
In this instance, $qtyValidFiles
has 4 values.
The code above returns:
#Games'#Movies'#Music'#TV'
which suggests to me that $tick
is always being seen as value 3
.