EACoder Help Center

EACoder
Help Center

EACoder

User Guide

Tutorials

Command List

FAQ

EACoder Operator and Command List v0.1

The following tables list and describe the php functions and operators which are available to users of EACoder for use in their EACoder scripts, as well as EACoder's special variables. In addition to a brief description, each entry also includes a syntax example in order to provide you with the ability to dive right into the function without further delay.


This is a prototype document and may not be complete in the information it relays about the functions available to users of EACoder. It is subject to revision at any time.


EACoder special variables

$xEACoder-supplied horizontal coordinate.$red = $x * $y;
$yEACoder-supplied vertical coordinate.$red = $x * $y;
$redOutput variable for red channel.$red = $x * $y;
$greenOutput variable for green channel.$green = $x * $y;
$blueOutput variable for blue channel.$blue = $x * $y;
$alphaOutput variable for alpha channel (transparency). Optional$alpha = $x;

Arithmetic Operators

The basic mathematical operators + - * / (plus minus times divide) work as you would expect, including the usual order of operations. By the way, % is actually the modulo operator in PHP - don't try to use it for division.



Assignment Operators

PHP's basic assignment operator is a single = symbol (note that == and === have entirely different meanings in PHP). In addition to being used on its own, = may be appended (tacked on) to a number of operators. This is a shorthand borrowed from the C programming language, and it works like this:

$x += 1; is equivalent to
$x = $x + 1;

The assignment operators are:
=+=-=*=/=%=^=|=&=<<=>>=.=

Advanced Mathematical Commands

pi()Returns pi.$x = pi();
abs()Absolute. Discards sign, so negative becomes positive and positive stays positive.$x = abs($y);
acos()Inverse cosine.$x = acos($y);
acosh()Inverse hyperbolic cosine.$x = acosh($y);
asin()Inverse sine.$x = asin($y);
asinh()Inverse hyperbolic sine.$x = asinh($y);
atan()Inverse tangent.$x = atan($a);
atan2()Quadrant-aware inverse tangent (takes two arguments).$t = atan2($y,$x);
atanh()Inverse hyperbolic tangent.$x = atanh($y);
cos()Cosine.$x = cos($y);
cosh()Hyperbolic cosine.$x = cosh($y);
exp()Returns e raised to a power.$x = exp($y);
log()Natural logarithm.$x = log($y);
log10()Base 10 logarithm.$x = log10($y);
pow()Power function$z = pow($x,$y);
sin()Sine.$x = sin($y);
sinh()Hyperbolic sine.$x = sinh($y);
sqrt()Square root.$x = sqrt($y);
tan()Tangent.$x = tan($y);
tanh()Hyperbolic tangent.$x = tanh($y);
bindec()Converts binary to decimal.$x = bindec($y);
decbin()Converts decimal to binary.$x = decbin($y);
dechex()Converts decimal to hexadecimal.$x = dechex($y);
decoct()Converts decimal to octal.$x = decoct($y);
deg2rad()Converts degrees to radians .$x = deg2rad($y);
hexdec()Converts hexadecimal to decimal.$x = hexdec($y);
octdec()Converts octal to decimal.$x = octdec($y);
rad2deg()Converts radians to degrees.$x = rad2deg($y);
rand()Returns a pseudo-random number between $min and $max$x = rand($min, $max);
srand()Seeds the random number generator.srand($x);
getrandmax()Returns the maximum value of rand().$x = getrandmax();
floor()Round down.$x = floor(2.543);
ceil()Round up.$x = ceil(2.543);
fmod()Floating-point modulo.$x = fmod($y, $z);
min()This command returns the smallest of the values which are given as parameters.$x=min($number1,
$number2, $number3);
max()This command returns the highest of the values which are given as parameters.$x=max($number1,
$number2, $number3);

Logical Operators

&&Logical AND.if ($x==1 && $y==2)
||Logical OR.if ($x==10 || $y==45)
!Logical NOT.if (!$x==6)
andLogical AND.if ($x==5 and $y==7)
orLogical OR.if ($x==5 or $y==3)
xorLogical XOR (exclusive OR).if ($x==4 xor $y==1)

Bitwise Operators

&Bitwise AND$x = $a & $b;
|Bitwise OR.$x = $a | $b;
^Bitwise XOR (exclusive OR).$x = $a ^ $b;
~Bitwise NOT$x = ~$a;
<<Bitshift left$x = $a << $b;
>>Bitshift right$x = $a >> $b;

Comparison Operators

==Equals.if ($x==1)
===Equivalence. Equal and of same data type.if ($x===1)
<Less than.if ($x<1)
>Greater than.if ($x>1)
<=Less than or equal.if ($x<=1)
>=Greater than or equal.if ($x>=1)

Control Structures

ifThe basic conditional.if ($x==1) {
$y=10;
}
elseifConditional else.if ($x==1) {
$y=10;
} elseif ($x>1) {
$y=20;
}
elseElse.if ($x==1) {
$y=10;
} else {
$y=30;
}
whileExecute codeblock whilever condition is TRUE.while ($x < 20) {
$x++;
}
do-whileSame as while, but condition is checked at the end of the codeblock instead of the start.do {
$x++;
} while ($x < 20);
forExecute codeblock while condition is TRUE, performing some change after each iteration. Typically used to execute a codeblock a predefined number of times.for ($counter=1;
$counter<=20;
$counter++) {
$x++;
}
foreachPerform the same actions on every variable in an array.foreach ($avar as $i) {
$r = $r * $i - $i;
}
breakBreak out of a loop early.while ($x < 20) {
$x++;
if ($x == 10) {
break;
}
}
continueSkip one iteration of a loop.while ($x < 20) {
$x++;
if ($x == 10) {
continue;
}
}

Array Functions

array()Store values in an array.$arr = array(1,2,3,4,5);
array_count_values()Count all values in an array.$arr2 = array_count_values($arr1);
array_product()Return the product of all values in an array.$product = array_product ($arr1);
array_rand()Pick random entries from an array.$r = array_rand($arr1);

or

$r = array_rand($arr1, 3);
array_sum()Return the sum of all values in an array.$r = array_sum($arr1);
in_array()Searches for a specific value in an array.$is_there = in_array($value, $array);
current()Returns the current array value.$current_value = current($arr1);
pos()Another name for current()$current_value = pos($arr1);
sort()Sort an array.sort ($arr1);
next()Return the next value in an array. Moves the internal array pointer.$next_value = next($array);
count()Returns the number of elements in an array.$len = count($arr1);
end()Returns the last value in an array. Moves the internal array pointer.$last_value = end($arr1);

Miscellaneous PHP

functionStructure for user-created functions.function sum($n) {
return $n/2 * ($n + 1);
}
++Short-hand for +=1. Commonly used with for$x++;
--Short-hand for -=1.$x--;

Notes