Pow(); This one is used to raise the power of a number. It has two parameters; the number and the power.
Pow(2,3); // This means 2 to the power of 3.
Rand(); This is used to generate a random number. It can be used without parameters, but the parameters are to set a range.
Say, I want the random number to be between 1 and 100.
Rand(1,100); Easy peasy.
Sqrt(64); // This will find the square root of a number. In this case, 64.
Ceil(); This function called "ceiling" is used to round a number up to a whole number. E.g. 5.5 will become 6. 4.3 will become 5.
floor(); This is the opposite of ceiling. Yep. Even in PHP. 4.4 will become 4. 5.8 will become 5.
round(); This one will round a number properly like we did in math. 4.4 will become 4, 4.6 will go up to 5.
String functions
Using these, you can do a lot with strings.
Let's see
<?php
$string = "yo yo yo yo";
strlen($string); // this calculates the number of characters in a string. Space included
strtoupper($string); // this changes the case of the string to UPPERCASE
strtolower($string); // lowercase
?>
Array functions
These functions will allow you to manipulate arrays. Make sure you remember them.
<?php
$list = [333,32,55,766,774,222,111]; // the cooler and better way to declare an array
max($list); // gets the maximum value in the array
sort($list); // sorts the array.
print_r($list); // print_r prints out the array. Useful if you want to see all the elements and their keys.
?>
That's all I can give you about functions for now. There are waaay more functions than I mentioned with different abilities. Some have similar uses. You can go to php.net to check out a whole universe of functions. We're getting really close to the good stuff. Getting data from forms next.

No comments:
Post a Comment