• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

PHP Paxton's Web Development School Part: 2

Calculator

PHP:
   <?php
function calculator1 ($num1,$num2)
{
return $num1+$num2;
}
echo calculator1 (1,5);
function calculator2 ($num3,$num4)
{
return $num3/$num4;
}
echo calculator2 (1,5);
function calculator3 ($num5,$num6)
{
return $num5*$num6;
}
echo calculator3 (1,5);

?>


LOOP!

PHP:
  <?

for($x = 0; $x<100; $x++) {
if($x%2)
echo $x."<br/>";
if($name == "math1")
break;
}

echo $name;

?>


Waiting for a 3rd one! :)


Cheers~
Leiken.
 
That's not exactly "table", but in PHP its called "array". Also it would be good if you would declare the variable as an array:
Code:
$var = array();
before writing it elements. ;)

Whats the disadvantage from Lua tables (as many people may be confused)?
In lua tables you may declare constants (ex. 1), key (ex. 2) and autokey (ex. 3)
Code:
local table = {bla = "lol"}
table.bla
Code:
local table = {"bla" = "lol"}
table["lol"]
Code:
local table = {"lol"}
table[1]
while in php you may use only key and autokey
Code:
$var = array("lol" => "lol");
$var['lol']
Code:
$var = array("lol");
$var[0]
also, Lua tables start with value 1, while php (whats actually standard...) with 0.

ejj bad techer want ban???? am wrajt local table = {"asd" = "lol"} ES WRONG mast wrajt local table = {["asd"] = "lol"} :mad:
 
1. :)
PHP:
<?

for($x = 1; $x<=100; $x++) {
if(($x+1)%2 != 0)
continue;

echo $x." ";
}

?>

2.

PHP:
   <?
function calculator($num1, $num2, $type)
{if($type == "sum") 
{
return $num1+$num2;

}
else if($type == "div")
{
return $num1/$num2;
}
else
return "Select a valid type (sum ,div)";
}
calculator($num1, $num2, $type);
echo calculator(7, 8 , "sulm");
?>
 
the first homework:

PHP:
<?
for($x=1, $x<=100, $x++)
echo "the last number is ".$x."<br>";

?>

why did u use <br />? isnt ok with <br>?

Second:
PHP:
<?
function calculator($num1, $num2, add) 
{
   if ($num1 == 0) {
   echo "You cant use 0";}
   elseif ($num2 == 0) {
   echo "you cant use 0";}
   else {
  return $num1+$num2}
  }
?>

didnt check them so please..tell me if they are ok

i didnt know what was ODD number :S

im waiting for part 3 :D
 
Last edited:
the first homework:

PHP:
<?
for($x=1, $x<=100, $x++)
echo "the last number is ".$x."<br>";

?>

why did u use <br />? isnt ok with <br>?

Second:
PHP:
<?
function calculator($num1, $num2, add) 
{
   if ($num1 == 0) {
   echo "You cant use 0";}
   elseif ($num2 == 0) {
   echo "you cant use 0";}
   else {
  return $num1+$num2}
  }
?>

didnt check them so please..tell me if they are ok

i didnt know what was ODD number :S

im waiting for part 3 :D

Param 'add' is not defined as variable, $ missing.
You can use if ($num1 == 0 || $num2 == 0).
 
This is phlua jaja
you code as if you were doing a lua script :(

but i think this will be useful to lots of ppl..
because we are in an Open Tibia community not in a php contest
jaja thanks :)
 
Lol i was bored and did:

PHP:
<?php
for( $x = 1; $x <= 999999999999999999999999999999999; $x++ )
echo $x."<br />";
?>

Then i lagged so mutch so i had to kill Firefox :'(

@Thread Great tutorial :]
 
Back
Top