views:

65

answers:

3

Hello I have the 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 that isn't correct. So for $k=8 I would have

$string[8] = $function[3]

How do I achieve this?

Thank you

A: 

Try this:

$string[$k] = $function[$k-5];

(Andrew Hare had already suggested that. But he deleted that for some reason.)

Gumbo
+2  A: 

Your version:

$string[$k] = $function[$(k-5)]

Correct version:

$string[$k] = $function[$k-5]
Prody
A: 

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];
dar7yl