increment an array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Goofan
Forum Contributor
Posts: 305
Joined: Wed Nov 04, 2009 2:11 pm
Location: Sweden

increment an array

Post by Goofan »

Hi,

So I have never wanted to increment an array element since I started programming but today I need to.

I got this code within a foreach statement.
Within the foreach statement I got a while loop.
The while loop uses the incrementation of the variable(change 2 array) to loop throught the code.

Now I thought about using a FOR loop.
But I need the value of the array index it's on to be incremented not the array index. How do I do it?

CODE:

Code: Select all

Foreach ($rid as $i){
     while ($comp[$i] <= $now){ //Lvl up the research until stop
	     //Calculate an addition of time per "lvl"
	     $ptf = ($ptf * ($lvl[$i] /2)) - $bet[$i];
	     $ptf = intval($ptf);
	     if ($ptf <= 0){
		     $ptf = 1;
	     }
	     $ptf = "+" .$ptf ." min"; 
	     //
						
	     $comp[$i] = date("Y-m-d H:i:s", strtotime ($comp[$i] .$ptf));
	     $lvl[$i]++;
							
	     //If last time stamp passed then exit while loop & add data to database
     }
}
The incrementation on the $lvl[$i] is putting out an error:
Fatal error: Cannot increment/decrement overloaded objects nor string offsets in C:\Test\index.php on line 71

I get that there becomes an error from that but I don't know how to fix it.

Regards,
Thomas
User avatar
Goofan
Forum Contributor
Posts: 305
Joined: Wed Nov 04, 2009 2:11 pm
Location: Sweden

Re: increment an array

Post by Goofan »

NVM! :D

Actually do work as I did just forgot to make the $lvl an array ^^

Regards,
Thomas
Post Reply