Finals Notes
Finals Notes
Associative Array:
:- In PHP, an associative array is a collection of key-value pairs, where each key is unique and associated
with a specific value.
To create an associative array, you can use the array() function with key-value pairs as arguments, like
this:
Key Value
Example: $person = array("name" => "John", "age" => 30, "city" => "New York");
You can access the values of an associative array by using the key, like this:
Index Array:
An index array, is a collection of values that are accessed by their numeric index. You can create an index
array by using the array() function with values as arguments, like this:
You can access the values of an index array by using the index, like this:
Data Visibility Data is visible in the URL Data is not visible in the URL
Data Type Can only send ASCII characters Can send binary data
Port HTTP uses Port 80 by default HTTPS uses Port 443 by default
Encryption HTTP does not use encryption HTTPS uses SSL/TLS encryption to protect the data
transmitted over the internet.
URL URLs that begin with "http://" are unencrypted URLs that begin with "https://" are encrypted, and
and can be intercepted by third parties. any data transmitted between the client and
server is protected.
Default HTTP is the default protocol for most websites, as HTTPS is used for websites that require additional
it is faster and does not require the installation of security measures, such as online banking, e-
an SSL certificate. commerce, and social media sites that require user
login information.
Speed HTTP is slightly faster than HTTPS HTTPS is slightly slower than HTTP due to the
additional overhead of SSL/TLS encryption.
SQL Query
SQL (Structured Query Language) is a programming language used to manage and manipulate relational
databases. An SQL query is a statement that is written in SQL syntax and is used to retrieve, insert,
update, or delete data from a database.
An SQL query can be used to perform a wide range of database operations, such as:
An SQL query consists of a series of clauses that specify condition. These clauses include keywords like
SELECT, FROM, WHERE, GROUP BY, ORDER BY, and others.
Here's an example of a basic SQL query that retrieves all records from a table named "customers":
1. Initialization: This part initializes a counter variable before the loop starts.
2. Condition: This part checks the condition before each iteration of the loop. If the condition is
true, the loop continues to execute. If it's false, the loop terminates.
3. Increment: This part updates the counter variable after each iteration of the loop.
Here's an example of a for loop that prints the numbers from 1 to 10:
echo $i . "<br>";
Foreach Loop: The foreach loop is used when you need to iterate over the elements of an array or an
object.
It automatically assigns the value of each element to a variable on each iteration of the loop.
Major Difference
One key difference between the for loop and the foreach loop is that the for loop requires you to
manually initialize and update the counter variable, while the foreach loop automatically iterates over
the elements of an array or object. This makes the foreach loop more convenient to use when working
with arrays and objects.
1. $_SERVER: This variable contains information about the web server and the current request
2. $_GET: This variable contains data that was sent to the PHP script through the HTTP GET
method.
3. $_POST: This variable contains data that was sent to the PHP script through the HTTP POST
method.
4. $_REQUEST: This variable contains data that was sent to the PHP script through either the GET
or POST methods.
5. $_SESSION: This variable contains data that is stored across multiple requests by the same
client.
6. $_COOKIE: This variable contains data that was sent to the PHP script in an HTTP cookie.
7. $_FILES: This variable contains information about files that were uploaded to the PHP script
using the HTTP POST method.
Cookies
Cookies: are small pieces of data that are stored on the client's computer and can be used to store
information such as login credentials or user preferences.
To set a cookie in PHP, you can use the setcookie() function. This function takes three parameters:
To retrieve a cookie in PHP, you can use the $_COOKIE superglobal variable.
These functions are available in PHP by default and can be used without the need for any additional
libraries or modules.
Here are some of the most commonly used array sorting functions in PHP:
1. sort(): This function sorts an array in ascending order based on the value of each element.
2. rsort(): This function sorts an array in descending order based on the value of each element.
3. asort(): This function sorts an array in ascending order based on the value of each element,
while maintaining the key-value associations.
4. arsort(): This function sorts an array in descending order based on the value of each element,
while maintaining the key-value associations.
5. ksort(): This function sorts an array in ascending order based on the key associated with each
element.
6. krsort(): This function sorts an array in descending order based on the key associated with each
element.
7. usort(): This function allows you to define your own comparison function to sort the array.
8. uasort(): This function allows you to define your own comparison function to sort the array,
while maintaining the key-value associations.
9. uksort(): This function allows you to define your own comparison function to sort the array
based on the key associated with each element.
Php code for inserting, deleting & updating.
Insertion Data:
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
$sql = "INSERT INTO MyGuests (firstname, lastname, email) VALUES ('John', 'Doe',
'[email protected]')";
if (mysqli_query($conn, $sql)) {
} else {
mysqli_close($conn);
Deleting Data:
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
if (mysqli_query($conn, $sql)) {
} else {
mysqli_close($conn);
Updating Data:
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
if (mysqli_query($conn, $sql)) {
} else {
mysqli_close($conn);