Operator | Description | Example | Result |
---|---|---|---|
. | Concatenation | $str1 . $str2 | Concatenation of $str1 and $str2 |
.= | Concatenation assignment | $str1 .= $str2 | Appends the $str2 to the $str1 |
<?php
$x = "Hello";
$y = " World!";
echo $x . $y; // Outputs: Hello World!
$x .= $y;
echo $x; // Outputs: Hello World!
?>
PHP Array Operators
The array operators are used to compare arrays:
Operator | Name | Example | Result |
---|---|---|---|
+ | Union | $x + $y | Union of $x and $y |
== | Equality | $x == $y | True if $x and $y have the same key/value pairs |
=== | Identity | $x === $y | True if $x and $y have the same key/value pairs in the same order and of the same types |
!= | Inequality | $x != $y | True if $x is not equal to $y |
<> | Inequality | $x <> $y | True if $x is not equal to $y |
!== | Non-identity | $x !== $y | True if $x is not identical to $y |
<?php echo ($age < 18) ? 'Child' : 'Adult'; ?>
<?php $name = isset($_GET['name']) ? $_GET['name'] : 'anonymous'; ?>
PHP Functions for Sorting Arrays:
sort()
andrsort()
— For sorting indexed arraysasort()
andarsort()
— For sorting associative arrays by valueksort()
andkrsort()
— For sorting associative arrays by key
Round a Fractional Value up or down
ceil(): round a fractional value up;
floor(); round a fractional value down;
rand(); generate some random numbers; //rand(1,10)
PHP Get and Post:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Example of PHP GET method</title>
</head>
<body>
<?php
if(isset($_GET["name"])){
echo "<p>Hi, " . $_GET["name"] . "</p>";
}
?>
<form method="get" action="<?php echo $_SERVER["PHP_SELF"];?>">
<label for="inputName">Name:</label>
<input type="text" name="name" id="inputName">
<input type="submit" value="Submit">
</form>
</body>
Note: $_SERVER["PHP_SELF"] call the php inside this URL;
Running PHP code on Terminal window:
sudo php -f filename.php
sudo php -f filename.php
Login mysql: mysql -u root -p
Rename file in Linux: sudo mv original_filename new_filename
No comments:
Post a Comment