Language features Flashcards
echo
outputs strings
.
concatenation
$var
php variable declaration requires $ at the front
$array
arrays are declared by creating a variable, newing up an array, and passing args.
$array = array(“Egg”, “Tomato”, “Bacon”);
array_push
adds to array
unset()
removes an item from array
strlen()
length of a string
substr()
part of a string
strtoupper()
uppercase a string
strtolower()
lowercase a string
strpos()
gives the first occurence of a character in a string
round()
rounds to nearest whole number
OPTIONAL: pass number of places to round to
join(glue, array)
joins an array into a string, with “glue” chars
sort()
sorts an array
rsort()
reverse sorts an array
public function __construct()
php class constructor function
is_a()
object method to test if an object is an instance of a class
(first arg is obj we’re checking, second is class)
property_exists()
check if an object has a given property (first arg is obj we’re checking, second is prop)
method_exists()
see if an object has a given method (first arg is obj we’re checking, second is method)
extends
keyword for inheritance i.e. class Square extends Shape {}
final
keyword to prevent parent class methods from being overridden by its children
const
constant variables
does not start with $
accessed via scope resolution operator
i.e. echo Ninja::stealth;
static
lets you use a class property or method without having to create an instance of that class. i.e. King::proclaim();
associative array
‘key’ => ‘value’ pair
aka a dictionary
multidimensional array
array of arrays
::
scope resolution operator
allows access to static, constant, and overridden props or methods of a class
->
access object member (props or methods)
equivalent to “.” in C# or JS