seany123 Posted November 9, 2009 Share Posted November 9, 2009 is anyone able to explain what this code is saying? i had it written for me awhile back and now that i wanna change it about to make it my own etc i dont really know what each part is doing... esspecially the += part lol. im using a form which includes this: <input type="hidden" name="item_name" value="50 Awake Pills" /> and then from the form above this code is used: $total = ereg_replace( "[^A-Za-z0-9]", "", $_REQUEST['item_name'] ); $total += 0; for ( $i = 0; $i < $total; $i++ ) Quote Link to comment https://forums.phpfreaks.com/topic/180846-what-does-this-mean/ Share on other sites More sharing options...
ram4nd Posted November 9, 2009 Share Posted November 9, 2009 "$total += 0;" adds 0 to variable "$total". What is pointless. Quote Link to comment https://forums.phpfreaks.com/topic/180846-what-does-this-mean/#findComment-954063 Share on other sites More sharing options...
KevinM1 Posted November 9, 2009 Share Posted November 9, 2009 More to the point, += is shorthand for writing: $total = $total + 0; There are other similar shorthand operators, including -=, *=, and even .= Quote Link to comment https://forums.phpfreaks.com/topic/180846-what-does-this-mean/#findComment-954066 Share on other sites More sharing options...
ram4nd Posted November 9, 2009 Share Posted November 9, 2009 What does *= do? Quote Link to comment https://forums.phpfreaks.com/topic/180846-what-does-this-mean/#findComment-954067 Share on other sites More sharing options...
seany123 Posted November 9, 2009 Author Share Posted November 9, 2009 What does *= do? im guessing *= is the same as += except you * it instead of + it. lol what about this part: for ( $i = 0; $i < $total; $i++ ) Quote Link to comment https://forums.phpfreaks.com/topic/180846-what-does-this-mean/#findComment-954069 Share on other sites More sharing options...
salathe Posted November 9, 2009 Share Posted November 9, 2009 Please see PHP Operators, in particular the Arithmetic and Assignment operators for things like += and *=. For ++, see incrementing/decrementing. For for see the for control structure. Quote Link to comment https://forums.phpfreaks.com/topic/180846-what-does-this-mean/#findComment-954073 Share on other sites More sharing options...
cags Posted November 9, 2009 Share Posted November 9, 2009 *= $value is the same as $total = $total * $value. .= $value is the same as $total = $total . $value or even $total = "$total$value" for ( $i = 0; $i < $total; $i++ ) is saying while $i is less than $total, loop, adding 1 to $i on each iteration ($i++ is the same as $i = $i + 1). It could also be written as $i = 0; while($i < $total) { $i++; } Faux Edit: But I recommend reading the links provided by salathe. Quote Link to comment https://forums.phpfreaks.com/topic/180846-what-does-this-mean/#findComment-954074 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.