Skip to content
Advertisement

PHP make array element 1.5 bigger than previous one

I have a code below. It needs to make array element 1.5 bigger than previous one. Expected outcome should be … 1, 1.5, 2.25, 3.375.. and so on but i get error (undefined offset)

JavaScript

But it doesn’t seem to work. What my code should look like.

Advertisement

Answer

Your array is empty to start with, so $array[$i] * 1.5 will not work. Initialize your array with at least one number to start with. Use $array[$i-1] for the previous element

JavaScript

will output:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement