PHP Unit1 Prep
PHP Unit1 Prep
PHP Unit1 Prep
Introduction to PHP
PHP (Hypertext Preprocessor) is a server-side scripting language
designed for web development but can also be used as a
general-purpose programming language. It is embedded in HTML and
works with web servers to create dynamic web pages.
or
Why is it popular?
PHP plays nicely with a lot of external systems. Here are some key
ways it integrates:
1. Database Systems
PHP can interact with external APIs to fetch or send data. For example:
● Weather APIs
● Payment gateways (e.g., PayPal, Stripe)
Imagine you’re at a restaurant (your app) and you wanna order some
food (data/functionality) from the kitchen (another app/system). You
don’t go into the kitchen yourself, right? You tell the waiter (API) what
you want, and they bring it to you.
4. Email Systems
PHP Scripting
PHP scripting refers to writing PHP code that runs on a web server to
create dynamic web pages or handle server-side tasks.
By using these functions, you can easily check the type of a variable
and output or process data accordingly in PHP!
In PHP, you can change the type of a variable using type casting or
type coercion.
Explanation:
● (int) casts the string "85.5" to an integer, so the value
becomes 85.
● (float) casts the string "85.5" to a float, keeping the decimal.
Explanation:
So if you want to force a change, you use explicit casting, but PHP
will do it for you automatically in many cases with implicit conversion.
1. Operators in PHP
Operators are symbols that perform operations on variables and
values. They can be classified into several types:
Example:
Example:
2. Variable Manipulation
Variable manipulation refers to modifying or operating on variables
directly, often using the operators mentioned above.
In this example:
3. Dynamic Variables
Dynamic variables are variables whose names are determined during
the program's execution. You can create variables with dynamic names
using the variable variables feature.
Here, $$varName is a dynamic variable. The value of $varName
(heroName) becomes the name of the new variable, and it is assigned
the value "Iron Man".
4. Variable Scope
Variable scope refers to the context in which a variable is accessible. In
PHP, there are three main types of variable scope:
Example:
Example: