<?php
//I have an array like this
$ar = array('0', '1', '2', '3', '4', '5');
for($i = 0; $i < count($ar); $i++)
{
echo $ar[$i+1]; //way1
echo $ar[$i] +=1 //way2
}
?>
So is it different between way1 and way 2 because i saw the same result ???
<?php
//I have an array like this
$ar = array('0', '1', '2', '3', '4', '5');
for($i = 0; $i < count($ar); $i++)
{
echo $ar[$i+1]; //way1
echo $ar[$i] +=1 //way2
}
?>
So is it different between way1 and way 2 because i saw the same result ???
Please clarify what exactly you're looking for here.
These two are totally different approaches and give you different results when your array values are something else.
echo $ar[$i+1]; // Means you're printing the values corresponding to array keys 1, 2, 3.....
echo $ar[$i] +=1 // Means you're getting the values of keys 0, 1, 2... and adding 1 to each of the values.
If you have an array $ar = array(3, 6, 2, 10), these two will work this way:
echo $ar[$i+1]; // 6, 2, 10 ....
echo $ar[$i] +=1 // 4, 7, 3, 11....
Hope this helps.
Peace! xD