Jump to content

for every number, add +50


newb

Recommended Posts

i have a number string which is any random integer of 1-10.

 

how can i make it so that if the string turns out to be 5, there will be 50 added on for every number under it. for example:

 

$string = '5';

 

1: +0

2: +50

3: +50

4: +50

5: +50

 

etc etc..

 

can anyone help?

Link to comment
Share on other sites

Could you show the actual numbers inside 0:, 1:, 2:, etc.?

 

yes the actual numbers would be

 

1: 50

2: 100

3: 150

4: 200

5: 250

 

Also, what would those numbers be if the number string was not 5 but rather 8?

 

they would just continue to add on

Link to comment
Share on other sites

So you want a loop that loops X times (5 or 8 in our story so far), and prints out 50, 100, etc?

 

foreach ($i = 1; $i <= $number_of_values; $i++) echo $i * 50;

 

I renamed $string to $number_of_values, I think it is a better name.

Link to comment
Share on other sites

ok im getting close: the problem is that it is adding +50 on the first value which is 1 (i dont want this)

 

anyway to fix this? i just want it to add +50 to the all the other values except the first

 

so it should be as.

 

1. +0

2. +50

3. +50

 

etc etc.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.