I am writing a PHP function that will take an array in the following format:
array( 'one', 'two', 'three' )
And repeat the following lines:
one one-two one-two-three
I canβt figure out how to do this. I tried using a variable to save the previous one and then using it, but it only works for one thing:
$previous = null; for($i = 0; $i < count($list); $i++) { echo ($previous != null ? $route[$previous] . "-" : '') . $route[$i]; $previous = $i; }
Withdrawal:
one two two-three
This approach is likely to be ineffective anyway, since this script should technically be able to handle any length of the array.
Does anyone help?
source share