PHP Changing index of variable
$string[$k] = $function[$k]
defined within a foreach loop with index $k. I want $string to be defined as
$string[$k] = $function[$(k-5)]
except t开发者_开发问答hat isn't correct. So for $k=8 I would have
$string[8] = $function[3]
How do I achieve this?
Thank you
Your version:
$string[$k] = $function[$(k-5)]
Correct version:
$string[$k] = $function[$k-5]
Try this:
$string[$k] = $function[$k-5];
(Andrew Hare had already suggested that. But he deleted that for some reason.)
Question: Is $function an array[] or a function() call?
If $function is an array, you must not access $function[k-5] where k<5;
your for loop should read:
for ($k=5; $k<$limit; ++k)
$string[$k] = $function[$k-5];
精彩评论