Results: 132
PHP / JavaScript differences
PHP variable declaration
$variable = 1;
JS alternative
let variable = 1;
PHP - check if the variable exists
if (isset($variable))
JS alternative
if (typeof variable !== "undefined")
PHP count array elements
$count = count([2, 3, 4]);
JS alternative
let count = [2, 3, 4].length;
PHP count letters in the string
$len = strlen('some string');
JS alternative
let len = 'some string'.length;
PHP absolute value of a given number
$variable = abs(-5);
JS alternative
let variable = Math.abs(-5);
PHP - power of a number
$square = pow(5, 2);
JS alternative
let square = Math.pow(5, 2);
PHP - square root of a number
$square_root = sqrt(16);
JS alternative
let square_root = Math.sqrt(16);
PHP - minimum number
$max = min(2, 3, 4);
JS alternative
let max = Math.min(2, 3, 4);
PHP - maximum number
$max = max([2, 3, 4]);
JS alternative
let max Math.max(...[2, 3, 4])
PHP calculates sum of the array elements
$sum = array_sum([2, 3, 4]);
JS alternative
let sum = 0;
let arr = [1, 2, 3];
for (let value of arr) {
    sum += value;
}
Another way to calculate the same
let arr = [1, 2, 3];
let sum = 0;
let len = arr.length;
for (let i = 0; i < len; sum += arr[i++]);
PHP - string position
$pos = strpos('Hello world', 'world');
JS alternative
let pos = 'Hello world'.indexOf('world');
PHP - edit letter in a string
$string[4] = 'X';
JS alternative
string = string.substring(0, 4) + 'X' + string.substring(5);
PHP convert the variable to integer
$variable = intval(5.5);
JS alternative
let variable = parseInt(5.5);
PHP - explode the sentence
$sentence = "Lorem ipsum dolor st amet";
$words = explode(" ", $sentence);
JS alternative
let sentence = "Lorem ipsum dolor st amet";
let words = sentence.split(" ");
else-if example for fun CODE
Don't create variables with Georgian alphabet. The following example is just for fun!
$სწავლა_გვინდა = true;
$ვაბარებთ_უნივერსიტეტში = true;
$სწავლა_ძვირია = true;
$მუშაობა_გვინდა = false;

if ($სწავლა_გვინდა) {
	if ($ვაბარებთ_უნივერსიტეტში) {
		if ($სწავლა_ძვირია) {
			echo "\nუნივერსიტეტი ძვირია, ვიწყებთ სწავლას applications.ge-ს კურსზე!";
		} else {
			echo "\nვსწავლობთ უნივერსიტეტში!";
		}
	} else {
		echo "\nვიწყებთ სწავლას applications.ge-ს კურსზე!";
	}
} elseif ($მუშაობა_გვინდა) {
	echo "\nვმუშაობთ";
} else {
	echo "\nდროს ნუ კარგავ!";
}
The
continue
statement breaks only one iteration in the loop and continues with the next iteration
for ($x = 0;  $x < 10;  $x++) {
  if ($x == 7) {
    continue;
  }
  echo "$x"."\n";
}
echo "\n\n";
Prints Only numbers evenly divisible by 2
for ($x = 0;  $x < 10;  $x++) {
  if ($x%2 == 1) {
    continue;
  }
  echo "Example2: $x"."\n";
}
The
break
statement is used to jump out of loops
for ($x = 0;  $x < 10;  $x++) {
  if ($x == 7) {
    break;
  }
  echo "$x"."\n";
}
Another example using
break
statement In this example prints numbers less than 6
for ($x = 0;  $x < 10;  $x++) {
  if ($x*$x > 30) {
    break;
  }
  echo "$x"."\n";
}
Uses
break
statement instead of for loop condition section
for ($i = 0;  ;  $i ++) {
  if ($i == 10) {
    break;
  }
  echo $i . "\n";
}
Logical operators are used to combine conditional statements.
and
($x and $y) True if both $x and $y are true
$x = 40; 
$y = 50;
if ($x > 30 and $y > 45) {
    echo "True";
}
or
($x or $y) True if either $x or $y is true
$x = 40; 
$y = 50;
if ($x > 30 or $y == 85) {
    echo "True";
}
xor
($x xor $y) True if either $x or $y is true, but not both
$x = 40; 
$y = 50;
if ($x > 30 xor $y == 85) {
    echo "True";
}
&&
($x && $y) True if both $x and $y are true
$x = 40; 
$y = 50;
if ($x > 30 and $y > 45) {
    echo "True";
}
||
($x || $y) True if either $x or $y is true
$x = 40; 
$y = 50;
if ($x > 30 or $y == 85) {
    echo "True";
}
!
(!$x) True if $x is not true
$x = 40;
if ($x !== 50) {
    echo "True";
}
==
(Equal) Returns true if $x is equal to $y
$x = 40; 
$y = "40";
var_dump($x == $y); // true
===
(Identical) Returns true if $x is equal to $y, and they are of the same type
$x = 40; 
$y = "40";
var_dump($x === $y); // false
!=
(Not equal) Returns true if $x is not equal to $y
$x = 40; 
$y = "40";
var_dump($x != $y); // false
<>
(Not equal) Returns true if $x is not equal to $y
$x = 40; 
$y = "40";
var_dump($x <> $y); // false
!==
(Not identical) Returns true if $x is not equal to $y, or they are not of the same type
$x = 40; 
$y = "40";
var_dump($x !== $y); // true
>
(Greater than) Returns true if $x is greater than $y
$x = 40; 
$y = 50;
var_dump($x > $y); // false
<
(Less than) Returns true if $x is less than $y
$x = 40; 
$y = 50;
var_dump($x < $y); // true
>=
(Greater than or equal to) Returns true if $x is greater than or equal to $y
$x = 40; 
$y = 50;
var_dump($x >= $y); // false
<=
(Less than or equal to) Returns true if $x is less than or equal to $y
$x = 40; 
$y = 50;
var_dump($x <= $y); // true
Assignment operators are used with:
integer
and
float
values to write / update a variable value. Simple Assignment
$y = 9;
$x = $y;
echo $x . "\n";
Addition
$x = 40; $y = 9;
$x += $y; // same as: $x = $x + $y
echo $x . "\n";
Subtraction
$x = 40; $y = 9;
$x -= $y; // $x = $x - $y
echo $x . "\n";
Multiplication
$x = 40; $y = 9;
$x *= $y; // $x = $x * $y
echo $x . "\n";
Division
$x = 40; $y = 9;
$x /= $y; // $x = $x / $y
echo $x . "\n";
Modulus
$x = 40; $y = 9;
$x %= $y; // $x = $x % $y
echo $x . "\n";
Comparing two double numbers
The following code executes the
else
statement because the
float
numbers are different
if (strval(0.000000000035436064) == strval(0.000000000035436064000001)) {
    echo 'if';
} else {
    echo 'else';
}
But if we add one
0
in front of the last digit of the second number, then
if
statement will be executed
if (strval(0.000000000035436064) == strval(0.0000000000354360640000001)) {
    echo 'if';
} else {
    echo 'else';
}
Note:
The above code is one of the best solutions to compare float numbers
call file_get_content() function with headers
First we create an array with the headers
$opts = [
	"http" => [
		"method" => "GET",
		"header" => 
			"Channel-Name: ".CHANNEL."\r\n" .
			"Authorization: ".AUTHORIZATION."\r\n"
	]
];
// Then we create a stream
$context = stream_context_create($opts);
Then we pass the
$content
to
file_get_contents()
function as the
third
parameter
$result = file_get_contents($url, false, $context);
http / https
If the URL starts with
https
it will make a request on
443
$ch = curl_init("https://xdatavpn.example.com/Bank");
If it starts with
http
the request will use
80
port
$ch = curl_init("http://xdatavpn.example.com/Bank");
Results: 132