Jump to content

[SOLVED] Incrementing in a loop


Rushy

Recommended Posts

Hey all,

 

another quick question.

 

I need to add a number to <book></book> every time this piece of code loops. I.e. <book1></book1> then <book2></book2>

 

    
echo fwrite($file,"<customer><fname>$_GET[fName]</fname><lname>$_GET[lName]</lname><email>$_GET[Email]</email></customer>");
foreach($_COOKIE as $cookie){
    echo fwrite($file, "<books><book>\"$cookie\"</book></books>");
}

 

Could someone please tell me how to do this? I researched it but I can't seem to get it to work :(

Link to comment
https://forums.phpfreaks.com/topic/76932-solved-incrementing-in-a-loop/
Share on other sites

    echo fwrite($file,"<customer><fname>$_GET[fName]</fname><lname>$_GET[lName]</lname><email>$_GET[Email]</email></customer>");
foreach($_COOKIE as $cookie){ 
    ++$cnt;// set a counter 
	echo fwrite($file, "<books".$cnt."><books".$cnt.">\"$cookie\"</books".$cnt."</books".$cnt.">");
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.