Login Register






Tutorial [PHP] Tutorial Two Numbers filter_list
Author
Message
[PHP] Tutorial Two Numbers #1
So, using numbers in php is very easy. Remember though coding always starts from 0 not one.

So to add lets say 1 + 1 you'd do it like this.

PHP Code:
<?PHP $number1 = 1; $number2 = 1; $number3 = $number1 + $number2; echo $number3; ?>

This would just echo out "2" that's all.

Lets say if you'd like to multiple 5 by 5 you'd do it like this.

PHP Code:
<?PHP $number1 = 5; $number2 = 5; $number3 = $number1 * $number2; echo $number3; ?>

See I am using * to multiple it, and not a x. But all this will echo out is "25".

There are a lot more witch you should be able to work out on your own.

Note: If you need any help and I have not yet made a tutorial for it please visit php.net.

Reply

RE: [PHP] Tutorial Two Numbers #2
You should mention that you are using 'operators', not just 'adding' or 'multiplying' numbers.

Reply

RE: [PHP] Tutorial Two Numbers #3
(03-05-2013, 10:51 PM)Monksy Wrote: Wouldn't it be better to teach using functions? It's so much easier than having to edit $number1 + $number2 every time, plus you can use the "add()" function I created below as many times in the code as you want.

Code:
<?php function add($n1,$n2) { echo $n1 + $n2; } add(4,6); ?>

If you look at my other tutorials you'll see I have done on on functions.

Reply

RE: [PHP] Tutorial Two Numbers #4
Instead of using functions or so, if you only want to add by one, just write the variables name followed by ++. Also, you should put all your tutorials in one thread instead of making a bunch of them.

Reply

RE: [PHP] Tutorial Two Numbers #5
(06-20-2013, 08:27 PM)SQLi Wrote: Instead of using functions or so, if you only want to add by one, just write the variables name followed by ++. Also, you should put all your tutorials in one thread instead of making a bunch of them.

This isn't adding by one though.
But yes, $int++; works perfectly.
[Image: BAvhP6h.png]
Code:
[5:42:25 PM] i0xillusi0n: Breshie don't bust a nut over chloe now [5:42:31 PM] Entity: fapfapfapfapfapfapfapfapfapfap [5:42:33 PM] Jigglypuff | SL: EWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW

Reply

RE: [PHP] Tutorial Two Numbers #6
(06-20-2013, 09:21 PM)i0xIllusi0n Wrote: This isn't adding by one though.
But yes, $int++; works perfectly.

It isn't? Oh well.

Reply

RE: [PHP] Tutorial Two Numbers #7
(06-20-2013, 10:45 PM)SQLi Wrote: It isn't? Oh well.

It's not, because the other half of the thread is 5+5. And I'm pretty sure he wouldv'e said $number1++; if he wanted to show more about specifically adding 1, rather than any number in general.
[Image: BAvhP6h.png]
Code:
[5:42:25 PM] i0xillusi0n: Breshie don't bust a nut over chloe now [5:42:31 PM] Entity: fapfapfapfapfapfapfapfapfapfap [5:42:33 PM] Jigglypuff | SL: EWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW

Reply