PHP II Functions, Arrays
PHP II Functions, Arrays
krsort($age); rsort($numbers);
//a=>sort ascending =>value //2 4 6 11 22
//k=>sort ascending =>key
echo "<br>";
echo "<br>";
} }
?> ?>
PHP Loops
> Often when you write code, you want the same
block of code to run over and over again in a row.
Instead of adding several almost equal lines in a
script we can use loops to perform a task like this.
> In PHP, we have the following looping
statements:
PHP Loops
Adding parameters...
> To add more functionality to a function, we
can add parameters. A parameter is just like
a variable.
> Parameters are specified after the function
name, inside the parentheses.
PHP Functions - Parameters
PHP Functions - Parameters
PHP Functions - Parameters
<?php
$arr = array('Hello','World!','Beautiful','Day!');
echo implode(" ",$arr);
?>
▪ strlen() function returns the length of a string.
▪ str_word_count() function counts the number of words in a
string.
▪ strrev() function reverses a string.
▪ strpos() function searches for a specific text within a string. If a
match is found, the function returns the character position of
the first match. If no match is found, it will return FALSE.
▪ str_replace() function replaces some characters with some
other characters in a string.
▪ implode() function returns a string from the elements of an
array.
▪ explode() function breaks a string into an array
<?php
echo strlen("Hello world!");
echo "<br>";
echo str_word_count("Hello world!");
echo "<br>";
echo strrev("Hello world!");
echo "<br>";
echo strpos("Hello world!", "world");
echo "<br>";
echo str_replace("world", "Dolly", "Hello world!");
echo "<br>";
echo str_repeat("Wow",13);
Date & Time Functions
1) date() function formats a timestamp to a more
readable date and time.
2) checkdate()
3) mktime()
PHP Forms - $_GET Function
Notice how the URL carries the information after the file name.
PHP Forms - $_GET Function