IT WS03 Chapter 5 and 6
IT WS03 Chapter 5 and 6
More
Data Types in
PHP
Strings
In PHP, a string is a sequence of
characters. Strings can be created
using single quotes or double
quotes. Double quotes allow for the
use of escape sequences and
variable substitution.
Commonly used String Functions
in PHP
PHP provides
several built-in
functions for
working with
Commonly used String Functions
strlen
in PHP
This will replace all occurrences of the substring "fox" with the
substring "cat" within the string "The quick brown fox jumps
Using Strings to Represent Dates
This will convert the string "July 22, 2023" into a Unix timestamp.
Using Strings to Represent Dates
The date() function
The `date` function is used to
format a Unix timestamp into a
string representation of a date
and/or time. Here is an example
of using `date`:
Using Strings to Represent Dates
Setting the timezone
By default, PHP uses the server's timezone
when working with dates and times.
However, it is possible to set a different
timezone using the
`date_default_timezone_set` function. Here
is an example, if you want to set the default
timezone to "Asia/Manila" (Philippines). The
correct timezone identifier for Manila is
"Asia/Manila.“
Arrays
In PHP, an array is a
variable that can hold
multiple values. Arrays
can be used to store
related data, such as a
Creating an Array
Arrays can be created using
the `array` function or using
square brackets. Here is an
example of creating an array
using the `array` function:
Control
Structures in
PHP
Control Structures in PHP
2. If the condition is
true, the code block
inside the first set of
curly braces
immediately following
Here's how the if-else statement works:
3. If the condition is
false, the code block
inside the else clause
(the second set of
If-Else Statement | Example: