2

$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

0

3 Answers 3

2

Your version:

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

Correct version:

$string[$k] = $function[$k-5]
Sign up to request clarification or add additional context in comments.

Comments

0

Try this:

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

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

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.