OPERATION | SAME AS | NAME | WHAT DOES MAKES |
$a = $b | $a = $b | ASSIGNMENT | Assigns $a to $b |
$bX =& $a | $bX =& $a | REFERENCE | $bX = $a By reference |
$a += $b | $a = $a + $b | ADDITION | $a = $a + $b |
$a -= $b | $a = $a - $b | SUBTRACTION | $a = $a - $b |
$a *= $b | $a = $a * $b | MULTIPLICATION | $a = $a * $b |
$a /= $b | $a = $a / $b | DIVISION | $a = $a / $b |
$a %= $b | $a = $a % $b | MODULUS | $a = $a % $b |
ed48 |
<?php
/* - - - - - - - - - - - - - - - - - - - - - - -
Assignment operators
for numeric values
- - - - - - - - - - - - - - - - - - - - - - - */
$rn01 = 10;
$as01 = 922;
$vl01 = $as01 - $rn01;
$vr01 = 5;
// $vl01 += $vr01;
echo 'ADDITION<br>' .
'( ' . $vl01 . ' += ' . $vr01 . ' ) = ' . ($vl01 += $vr01) . '<br><br>';
// $vl01 -= $vr01;
echo 'SUBTRACTION<br>' .
'( ' . $vl01 . ' -= ' . $vr01 . ' ) = ' . ($vl01 -= $vr01) . '<br><br>';
// $vl01 *= $vr01;
echo 'MULTIPLICATION<br>' .
'( ' . $vl01 . ' *= ' . $vr01 . ' ) = ' .($vl01 *= $vr01) . '<br><br>';
// $vl01 / $vr01;
echo 'DIVISION<br>' .
'( ' . $vl01 . ' /= ' . $vr01 . ' ) = ' . ($vl01 /= $vr01) . '<br><br>';
// $vl01 %= $vr01;
echo 'MODULUS<br>' .
'( ' . $vl01 . ' %= ' . $vr01 . ' ) = ' . ($vl01 %= $vr01) . '<br><br>';
$rf01 =& $vr01;
echo 'REFERENCE TO THE VALUE OF $vr01 = ' . $vr01 . '<br>' .
'( ' . $vr01 . ' =& ' . $rf01 . ' ) = ' . $rf01 . '<br><br>';
?>
<?php
/* - - - - - - - - - - - - - - - - - - - - - - -
Assignment operators
for numeric values
- - - - - - - - - - - - - - - - - - - - - - - */
$a02 = PHP_FLOAT_MIN;
$b02 =& $a02;
$c02 =& $b02;
echo '$a02 = ' . $a02 .
'<br><br>$b02 = ' . $b02 .
'<br><br>$c02 = ' . $c02;
?>
OPERATOR | USE | NAME | WHAT DOES MAKES |
+ | $a + $b | ADDITION | Sum of $a and $b |
- | $a - $b | SUBTRACTION | Difference of $a and $b |
* | $a * $b | MULTIPLICATION | Product of $a and $b |
/ | $a / $b | DIVISION | Quotient of $a and $b |
% | $a % $b | MODULUS | Remainder of $a divided by $b |
** | $a ** $b | EXPONENTIATION | Result of raising $a to the $b'th power Since PHP 5.6.0 |
ed48 |
<?php
/* - - - - - - - - - - - - - - - - - - - - - - -
Arithmetic Operators
- - - - - - - - - - - - - - - - - - - - - - - */
$a03 = 92233720368547758;
$c03 = 2;
echo 'ADDITION<br>' .
'( ' . $a03 . ' + ' . $c03 . ' ) = ' . ($a03 + $c03);
echo '<br><br>SUBTRACTION<br>' .
'( ' . $a03 . ' - ' . $c03 . ' ) = ' . ($a03 - $c03);
echo '<br><br>MULTIPLICATION<br>' .
'( ' . $a03 . ' * ' . $c03 . ' ) = ' . ($a03 * $c03);
echo '<br><br>DIVISION<br>' .
'( ' . $a03 . ' / ' . $c03 . ' ) = ' . ($a03 / $c03);
echo '<br><br>MODULUS<br>' .
'( ' . $a03 . ' % ' . $c03 . ' ) = ' . $a03 % $c03;
echo '<br><br>EXPONENTIATION<br>' .
'( ' . $a03 . ' ** ' . $c03 . ' ) = ' . ($a03 ** $c03);
echo '<br><br>';
?>
OPERATOR | USE | NAME | RETURNS |
== | $a == $b | EQUAL | TRUE if $a is EQUAL to $b |
!= | $a != $b | NOT EQUAL | TRUE if $a is NOT EQUAL to $b |
<> | $a <> $b | ||
=== | $a === $b | IDENTICAL | TRUE if $a is INDENTICAL to $b |
!== | $a !== $b | NOT IDENTICAL | TRUE if $a is NOT INDENTICAL to $b |
> | $a > $b | GREATER THAN | TRUE if $a is GREATER than $b |
< | $a < $b | LESS THAN | TRUE if $a is LESS than $b |
>= | $a >= $b | GREATER THAN or EQUAL | TRUE if $a is GREATER than or EQUAL to $b |
<= | $a <= $b | LESS THAN or EQUAL | TRUE if $a is LESS than or EQUAL to $b |
<=> | $a <=> $b | SPACESHIP | Returns 0 if $a = $b |
Returns -1 if $a < $b |
|||
Returns 1 if $a > $b |
|||
ed48 |
<?php
/* - - - - - - - - - - - - - - - - - - - - - - -
Comparison Operators
Individualized
USER-DEFINED
comparison functions
- - - - - - - - - - - - - - - - - - - - - - - */
function isequal($par1, $par2)
{
if($par1 == $par2)
{
echo $par1 .
' is EQUAL to ' . $par2 . '<br>';
}
else
{
echo $par1 .
' is NOT EQUAL to ' . $par2 . '<br>';
}
}
function isnotequal($par1, $par2)
{
if($par1 != $par2)
{
echo $par1 .
' is NOT EQUAL to ' . $par2 . '<br>';
}
else
{
echo $par1 .
' is EQUAL to ' . $par2 . '<br>';
}
}
function isidentical($par1, $par2)
{
if($par1 === $par2)
{
echo $par1 .
' is IDENTICAL to ' . $par2 . '<br>';
}
else
{
echo $par1 .
' is NOT IDENTICAL to ' . $par2 . '<br>';
}
}
function isgreaterthan($par1, $par2)
{
if($par1 > $par2)
{
echo $par1 .
' is GREATER than ' . $par2 . '<br>';
}
else
{
echo $par1 .
' is NOT GREATER than ' . $par2 . '<br>';
}
}
function islessthan($par1, $par2)
{
if($par1 < $par2)
{
echo $par1 .
' is LESS than ' . $par2 . '<br>';
}
else
{
echo $par1 .
' is NOT LESS than ' . $par2 . '<br>';
}
}
function isgreaterthanorequal($par1, $par2)
{
if($par1 >= $par2)
{
echo $par1 .
' is GREATER than or EQUAL ' . $par2 . '<br>';
}
else
{
echo $par1 .
' is NOT GREATER than or EQUAL ' . $par2 . '<br>';
}
}
function islessthanorequal($par1, $par2)
{
if($par1 <= $par2)
{
echo $par1 .
' is LESS than or EQUAL ' . $par2 . '<br>';
}
else
{
echo $par1 .
' is NOT LESS than or EQUAL ' . $par2 . '<br>';
}
}
$a04 = 98.321;
$n04= 92.987;
$t04s = '"Non ducor duco."';
$t04t = '"Non ducor duco!"';
echo '- - - - - - - - - - - - - - - -<br>';
echo 'NUMBERS COMPARE<br>';
echo '- - - - - - - - - - - - - - - -<br><br>';
isequal($a04, $a04);
isequal($a04, $n04);
echo '<br><br>';
isnotequal($a04, $n04);
isnotequal($n04, $a04);
echo '<br><br>';
isidentical($a04, $n04);
isidentical($a04, $a04);
isidentical($n04, $n04);
echo '<br><br>';
isgreaterthan($a04, $n04);
isgreaterthan($n04, $a04);
echo '<br><br>';
islessthan($a04, $n04);
islessthan($n04, $a04);
echo '<br><br>';
isgreaterthanorequal($a04, $n04);
isgreaterthanorequal($n04, $a04);
isgreaterthanorequal($a04, $a04);
isgreaterthanorequal($n04, $n04);
echo '<br><br>';
islessthanorequal($a04, $n04);
islessthanorequal($n04, $a04);
islessthanorequal($a04, $a04);
islessthanorequal($n04, $n04);
echo '<br><br><br>- - - - - - - - - - - - - - - -<br>';
echo 'STRINGS COMPARE<br>';
echo '- - - - - - - - - - - - - - - -<br><br>';
isequal($t04t, $t04t);
isequal($t04s, $t04t);
echo '<br><br>';
isnotequal($t04s, $t04t);
isnotequal($t04t, $t04s);
echo '<br><br>';
isnotequal($t04s, $t04t);
isnotequal($t04t, $t04s);
echo '<br><br>';
isidentical($t04s, $t04t);
isidentical($t04s, $t04s);
isidentical($t04t, $t04t);
echo '<br><br>';
isgreaterthan($t04s, $t04t);
isgreaterthan($t04t, $t04s);
echo '<br><br>';
islessthan($t04s, $t04t);
islessthan($t04t, $t04s);
echo '<br><br>';
isgreaterthanorequal($t04s, $t04t);
isgreaterthanorequal($t04t, $t04s);
isgreaterthanorequal($t04t, $t04t);
isgreaterthanorequal($t04s, $t04s);
echo '<br><br>';
islessthanorequal($t04s, $t04t);
islessthanorequal($t04t, $t04s);
islessthanorequal($t04t, $t04t);
islessthanorequal($t04s, $t04s);
?>
<?php
/* - - - - - - - - - - - - - - - - - - - - - - -
Comparison Operators
A single
USER-DEFINED
comparison funtion
- - - - - - - - - - - - - - - - - - - - - - - */
function compare($par1, $par2)
{
if($par1 == $par2)
{
echo $par1 . ' is EQUAL to ' . $par2 . '<br><br>';
}
else
{
echo $par1 . ' is NOT EQUAL to ' . $par2 . '<br><br>';
}
if($par1 != $par2)
{
echo $par1 . ' is NOT EQUAL to ' . $par2 . '<br><br>';
}
else
{
echo $par1 . ' is EQUAL to ' . $par2 . '<br><br>';
}
if($par1 === $par2)
{
echo $par1 .
' is IDENTICAL to ' . $par2 . '<br><br>';
}
else
{
echo $par1 .
' is NOT IDENTICAL to ' . $par2 . '<br><br>';
}
if($par1 > $par2)
{
echo $par1 .
' is GREATER than ' . $par2 . '<br><br>';
}
else
{
echo $par1 .
' is NOT GREATER than ' . $par2 . '<br><br>';
}
if($par1 < $par2)
{
echo $par1 .
' is LESS than ' . $par2 . '<br><br>';
}
else
{
echo $par1 .
' is NOT LESS than ' . $par2 . '<br><br>';
}
if($par1 >= $par2)
{
echo $par1 .
' is GREATER than or EQUAL ' . $par2 . '<br><br>';
}
else
{
echo $par1 .
' is NOT GREATER than or EQUAL ' . $par2 . '<br><br>';
}
if($par1 <= $par2)
{
echo $par1 .
' is LESS than or EQUAL ' . $par2 . '<br><br>';
}
else
{
echo $par1 .
' is NOT LESS than or EQUAL ' . $par2 . '<br><br>';
}
}
$n02a = 92233720368547758;
$n02b = 92233720368547758;
$t02a = '"Non ducor duco."';
$t02b = '"Non ducor duco!"';
compare($n02a, $n02b);
compare($t02a, $t02b);
?>
<?php
/* - - - - - - - - - - - - - - - - - - - - - - -
Comparison Operators
A single
USER-DEFINED
spaceship comparison funtion
- - - - - - - - - - - - - - - - - - - - - - - */
function spacesh($par1, $par2)
{
if(($par1 <=> $par2) == 0)
{
echo $par1 . ' = ' . $par2 . '<br><br>';
}
elseif(($par1 <=> $par2) == -1)
{
echo $par1 . ' < ' . $par2 . '<br><br>';
}
elseif(($par1 <=> $par2) == 1)
{
echo $par1 . ' > ' . $par2 . '<br><br>';
}
}
$n02a = 922;
$n02b = 922;
$n02c = 9223;
$n02e = 9223.372;
$n02f = 9223.372;
$n02g = 9223.373;
spacesh($n02a, $n02b);
spacesh($n02a, $n02c);
spacesh($n02c, $n02a);
spacesh($n02e, $n02f);
spacesh($n02e, $n02g);
spacesh($n02g, $n02e);
?>
OPERATOR | NAME | DESCRIPTION |
++$a | PRE-INCREMENT | Increments $a by 1, then returns $a |
$a++ | POST_INCREMENT | Returns $a, then increments $a by 1 |
--$a | PRE-DECREMENT |
Decrements $a by 1, then returns $a |
$a-- | POST-DECREMENT | Returns $a, then decrements $a by 1 |
ed48 |
<?php
/* - - - - - - - - - - - - - - - - - - - - - - -
Increment
and
Decrement Operators
- - - - - - - - - - - - - - - - - - - - - - - */
$vl06a = 999;
$vl06b = 999;
$vl06c = 999;
$vl06d = 999;
echo 'PRE-INCREMENT<br>Given value = ' . $vl06a .
'<br>Increments ' . $vl06a . ' by 1, then returns ' . ++$vl06a .
'<br>CURRENT VALUE = ' . $vl06a . '<br><br>';
echo 'POST-INCREMENT<br>Given value = ' . $vl06b .
'<br>Returns ' . $vl06b . ' then increments ' . $vl06b .
' by 1, that is '. $vl06b++ .
'<br>CURRENT VALUE = ' . $vl06b . '<br><br>';
echo 'PRE-DECREMENT<br>Given value = ' . $vl06c .
'<br>Decrements ' . $vl06c . ' by 1, then returns ' . --$vl06c .
'<br>CURRENT VALUE = ' . $vl06c . '<br><br>';
echo 'POST-DECREMENT<br>Given value = ' . $vl06d .
'<br>Returns ' . $vl06d . ' then decrements ' . $vl06d .
' by 1, that is '. $vl06d-- .
'<br>CURRENT VALUE = ' . $vl06d . '<br><br>';
?>
OPERATOR | USE | NAME | WHAT DOES MAKES |
and | $a and $b | AND | Returns TRUE if both $a and $a are TRUE |
&& | $a && $b | ||
or | $a or $b | OR | Returns TRUE if either $a or $b is TRUE |
|| | $a || $b | ||
xor | $a xor $b | XOR | Returns TRUE if either $a or $b is TRUE, but NOT BOTH |
! | !$a | NOT | Returns TRUE if $a is not TRUE |
ed48 |
<?php
/* - - - - - - - - - - - - - - - - - - - - - - -
Logical Operators
- - - - - - - - - - - - - - - - - - - - - - - */
function if_and($pr1, $pr2, $v1, $v2)
{
if($pr1 == $v1 and $pr2 == $v2)
// if($pr1 == $v1 && $pr2 == $v2)
{
echo '(' . $pr1 . ' == ' . $v1 . ' and ' . $pr2 .' == ' . $v2 .')<br>';
echo '( Y ) AND is applicable<br><br>';
}
else
{
echo '(' . $pr1 . ' == ' . $v1 . ' and ' . $pr2 .' == ' . $v2 .')<br>';
echo '( N ) AND is NOT applicable<br><br>';
}
}
function if_or($pr1, $pr2, $v1, $v2)
{
if($pr1 == $v1 or $pr2 == $v2)
// if($pr1 == $v1 || $pr2 == $v2)
{
echo '(' . $pr1 . ' == ' . $v1 . ' or ' . $pr2 .' == ' . $v2 .')<br>';
echo '( Y ) OR is applicable<br><br>';
}
else
{
echo '(' . $pr1 . ' == ' . $v1 . ' or ' . $pr2 .' == ' . $v2 .')<br>';
echo '( N ) OR is NOT applicable<br><br>';
}
}
function if_xor($pr1, $pr2, $v1, $v2)
{
if($pr1 == $v1 xor $pr2 == $v2)
{
echo '(' . $pr1 . ' == ' . $v1 . ' xor ' . $pr2 .' == ' . $v2 .')<br>';
echo '( Y ) XOR is applicable<br><br>';
}
else
{
echo '(' . $pr1 . ' == ' . $v1 . ' xor ' . $pr2 .' == ' . $v2 .')<br>';
echo '( N ) XOR is NOT applicable<br><br>';
}
}
function if_not($pr1, $v1)
{
if($pr1 !== $v1)
{
echo '(' . $pr1 . ' !== ' . $v1 . ')<br>';
echo '( Y ) NOT EQUAL is applicable<br><br>';
}
else
{
echo '(' . $pr1 . ' !== ' . $v1 . ')<br>';
echo '( N ) NOT EQUAL is NOT applicable<br><br>';
}
}
$vl07a = 8;
$vl07b = 9;
if_and($vl07a, $vl07b, 8, 9);
if_and($vl07a, $vl07b, 8, 90);
if_or($vl07a, $vl07b, 8, 90);
if_or($vl07a, $vl07b, 80, 9);
if_or($vl07a, $vl07b, 80, 90);
if_xor($vl07a, $vl07b, 8, 90);
if_xor($vl07a, $vl07b, 80, 9);
if_xor($vl07a, $vl07b, 80, 90);
if_not($vl07a, 8);
if_not($vl07a, 9);
if_not($vl07b, 9);
if_not($vl07b, 8);
?>
OPERATOR | USE | NAME | WHAT DOES MAKES |
. | $str1 . $str2 | CONCATENATION | Performs the concatenation of $str1 and $str2 |
.= | $str1 .= $str2 | CONCATENATION ASSIGNMENT | Appends $str2 to $str1 |
=& | $strX =& $str1 | REFERENCE | By reference $strX = $str1 |
<=> | $str1 <=> $str2 | SPACESHIP | Returns 0 if $str1 = $str2 |
Returns -1 if $str1 < $str2 |
|||
Returns 1 if $str1 > $str2 |
|||
ed48 |
<?php
/* - - - - - - - - - - - - - - - - - - - - - - -
String Operators
- - - - - - - - - - - - - - - - - - - - - - - */
$str1 = 'It\'s six of one and ';
$str2 = 'half a dozen of the other.';
echo 'CONCATENATION<br>' . $str1 . $str2 . '<br><br>';
$str1 .= $str2;
echo 'CONCATENATION ASSIGNMENT<br>' . $str1 . '<br><br>';
$str3 =& $str1;
echo 'BY REFERENCE<br>' . $str3 . '<br><br>';
?>
<?php
/* - - - - - - - - - - - - - - - - - - - - - - -
STRING Operators
A single
USER-DEFINED
spaceshstrip comparison funtion
- - - - - - - - - - - - - - - - - - - - - - - */
function spaceshstr($par1, $par2)
{
if(($par1 <=> $par2) == 0)
{
echo $par1 . ' = ' . $par2 . '<br><br>';
}
elseif(($par1 <=> $par2) == -1)
{
echo $par1 . ' < ' . $par2 . '<br><br>';
}
elseif(($par1 <=> $par2) == 1)
{
echo $par1 . ' > ' . $par2 . '<br><br>';
}
}
$str08a = '"spaceship operator"';
$str08b = '"spaceship operator"';
$str08c = '"Spaceship Operator"';
$str08d = '"SPACESHIP OPERATOR"';
spaceshstr($str08a, $str08b);
spaceshstr($str08a, $str08c);
spaceshstr($str08c, $str08a);
spaceshstr($str08d, $str08a);
?>
OPERATOR | USE | NAME | WHAT DOES MAKES |
+ | $ar1 + $ar2 | UNION | UNION of $ar1 and $ar2 |
== | $ar1 == $ar2 | EQUALITY | Returns TRUE if $ar1 and $ar2 have the same key/value pairs |
!= | $ar1 != $ar2 | INEQUALITY | Returns TRUE if $ar1 is not equal to $ar2 |
<> | $ar1 <> $ar2 | ||
=== | $ar1 === $ar2 | IDENTITY | Returns TRUE if $ar1 and $ar2 have the same key/value pairs in the same order and of the same types |
!== | $ar1 !== $ar2 | NON IDENTITY | Returns TRUE if $ar1 is not identical to $ar2 |
=& | $arX !=& !$ar1 | REFERENCE | By reference $arX = $ar1 |
??= | $ar1['key'] ??= computeDefault() |
NULL COALESCING | Null coalescing assignment operator |
<=> | $ar1 <=> $ar2 | SPACESHIP | Returns 0 if $ar1 = $ar2 |
Returns -1 if $ar1 < $ar2 |
|||
Returns 1 if $ar1 > $ar2 |
|||
ed48 |
<?php
/* - - - - - - - - - - - - - - - - - - - - - - -
Array Operators
UNION
$ar1 + $ar2 will be
displayed with
ALL THE ELEMENTS of
$ar1 and $ar2,
since the indexes of the two
do not repeat themselves.
- - - - - - - - - - - - - - - - - - - - - - - */
$ar1 = [ 'K' => 2, 'L' => 8, 'M' => 18, 'N' => 32 ];
$ar2 = [ 'O' => 32, 'P' => 18, 'Q' => 8 ];
$ar12 = $ar1 + $ar2;
echo '<pre>';
print_r($ar12);
echo '</pre>';
/* - - - - - - - - - - - - - - - - - - - - - - - - - -
Array Operators
UNION
The elements from the
$ar1 will be used,
and the matching elements
from the $ar2 will be ignored.
- - - - - - - - - - - - - - - - - - - - - - - - - - - */
$ar3 = [ 2, 8, 18, 32 ];
$ar4 = [ 32, 18, 8 ];
$ar34 = $ar3 + $ar4;
echo '<pre>';
print_r($ar34);
echo '</pre>';
?>
<?php
function is_equality($par1, $par2)
{
if(($par1 == $par2) == TRUE)
{
echo '( ';
var_dump($par1);
echo ' == ';
var_dump($par2);
echo ' )<br><br>(TRUE) The ARRAYS have the
SAME key/value pairs.<br>No matter the order!<br><br>';
}
else
{
echo '( ';
var_dump($par1);
echo ' == ';
var_dump($par2);
echo ' )<br><br>(FALSE) The ARRAYS DOES NOT have the
SAME key/value pairs.<br><br>';
}
}
/* - - - - - - - - - - - - - - - - - - - - - - -
Array Operators
EQUALITY
The key/value pairs of
$ar5 and $ar6 have
different values.
- - - - - - - - - - - - - - - - - - - - - - - */
$ar5 = [ 'K' => 2, 'L' => 8, 'M' => 18, 'N' => 32 ];
$ar6 = [ 'O' => 32, 'P' => 18, 'Q' => 8 ];
is_equality($ar5, $ar6);
/* - - - - - - - - - - - - - - - - - - - - - -
Array Operators
EQUALITY
The key/value pairs of
$ar7 and $ar8 have
the same values,
no matter the order.
- - - - - - - - - - - - - - - - - - - - - - */
$ar7 = [ 'K' => 2, 'L' => 8, 'M' => 18, 'N' => 32 ];
$ar8 = [ 'K' => 2, 'N' => 32, 'L' => 8, 'M' => 18 ];
is_equality($ar7, $ar8);
?>
<?php
function is_identity($par1, $par2)
{
if(($par1 === $par2) == TRUE)
{
echo '( ';
var_dump($par1);
echo ' === ';
var_dump($par2);
echo ' )<br><br>(TRUE) The ARRAYS have the
SAME key/value pairs.<br>In the SAME order!<br><br>';
}
else
{
echo '( ';
var_dump($par1);
echo ' === ';
var_dump($par2);
echo ' )<br><br>(FALSE) The ARRAYS DOES NOT have the
SAME key/value pairs.<br><br>';
}
}
/* - - - - - - - - - - - - - - - - - - - - - - -
Array Operators
IDENTITY
The key/value pairs of
$ar9 and $ar10 have
different values.
- - - - - - - - - - - - - - - - - - - - - - - */
$ar9 = [ 'K' => 2, 'L' => 8, 'M' => 18, 'N' => 32 ];
$ar10 = [ 'O' => 32, 'P' => 18, 'Q' => 8 ];
is_identity($ar9, $ar10);
/* - - - - - - - - - - - - - - - - - - - - - - -
Array Operators
IDENTITY
The key/value pairs of
$ar11 and $ar12 have
the SAME values,
however, in different order
- - - - - - - - - - - - - - - - - - - - - - - */
$ar11 = [ 'K' => 2, 'L' => 8, 'M' => 18, 'N' => 32 ];
$ar12 = [ 'K' => 2, 'N' => 32, 'L' => 8, 'M' => 18 ];
is_identity($ar11, $ar12);
/* - - - - - - - - - - - - - - - - - - - - - -
Array Operators
IDENTITY
The key/value pairs of
$ar13 and $ar14 have
the same values,
in the SAME order.
- - - - - - - - - - - - - - - - - - - - - - */
$ar13 = [ 'K' => 2, 'L' => 8, 'M' => 18, 'N' => 32 ];
$ar14 = [ 'K' => 2, 'L' => 8, 'M' => 18, 'N' => 32];
is_identity($ar13, $ar14);
?>
<?php
function is_nonidentity($par1, $par2)
{
if(($par1 !== $par2) == TRUE)
{
echo '( ';
var_dump($par1);
echo ' !== ';
var_dump($par2);
echo ' )<br><br>(TRUE) The ARRAYS DOES NOT have the
SAME key/value pairs.<br><br>';
}
else
{
echo '( ';
var_dump($par1);
echo ' !== ';
var_dump($par2);
echo ' )<br><br>(FALSE) The ARRAYS have the
SAME key/value pairs.<br>In the SAME order!<br><br>';
}
}
/* - - - - - - - - - - - - - - - - - - - - - - -
Array Operators
IDENTITY
The key/value pairs of
$ar15 and $ar16 have
different values.
- - - - - - - - - - - - - - - - - - - - - - - */
$ar15 = [ 'K' => 2, 'L' => 8, 'M' => 18, 'N' => 32 ];
$ar16 = [ 'O' => 32, 'P' => 18, 'Q' => 8 ];
is_nonidentity($ar15, $ar16);
/* - - - - - - - - - - - - - - - - - - - - - - -
Array Operators
NON-IDENTITY
The key/value pairs of
$ar17 and $ar18 have
the SAME values,
however, in different order
- - - - - - - - - - - - - - - - - - - - - - - */
$ar17 = [ 'K' => 2, 'L' => 8, 'M' => 18, 'N' => 32 ];
$ar18 = [ 'K' => 2, 'N' => 32, 'L' => 8, 'M' => 18 ];
is_nonidentity($ar17, $ar18);
/* - - - - - - - - - - - - - - - - - - - - - -
Array Operators
NON-IDENTITY
The key/value pairs of
$ar19 and $ar20 have
the same values,
in the SAME order.
- - - - - - - - - - - - - - - - - - - - - - */
$ar19 = [ 'K' => 2, 'L' => 8, 'M' => 18, 'N' => 32 ];
$ar20 = [ 'K' => 2, 'L' => 8, 'M' => 18, 'N' => 32];
is_nonidentity($ar19, $ar20);
?>
<?php
/* - - - - - - - - - - - - - -
ARRAY Operators
- - - - - - - - - - - - - - -*/
$arr15 = [ 'K' => 2, 'L' => 8, 'M' => 18, 'N' => 32 ];
$arr16 = [ 'O' => 32, 'P' => 18, 'Q' => 8 ];
$narr15 =& $arr15;
$narr16 =& $arr16;
echo 'REFERENCE TO THE VALUE OF<br>$arr15 = ';
var_dump($arr15);
echo '<br>is<br>$narr15 = ';
var_dump($narr15);
echo '<br><br>REFERENCE TO THE VALUE OF<br>$arr16 = ';
var_dump($arr16);
echo '<br>is<br>$narr16 = ';
var_dump($narr16);
?>
<?php
/* - - - - - - - - - - - - - -
ARRAY Operators
- - - - - - - - - - - - - - -*/
function listarr($arr)
{
var_dump($arr);
echo '<br><br>';
}
$here = [ 'red', 'green'];
$arr15b = ['blue', 'yellow', 'black'];
$arr15 = [...$here, 'blue', 'yellow', 'black'];
listarr($here);
echo '<br>';
listarr($arr15b);
echo '<br>';
listarr($arr15);
?>
<?php
/* - - - - - - - - - - - - - -
ARRAY Operators
- - - - - - - - - - - - - - -*/
$data = [ 'title' => 'Lusiadas',
'subject' => 'An epic poem about the
Portuguese language, published in 1572.' ];
$data[ 'author' ] ??= 'Luiz Vaz de Camões';
var_dump($data);
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Null Coalescing Assignment Operator checks
if $author is NULL, if so it assign
string(19) "Luiz Vaz de Camões" to it.
Best benefit of
Null Coalescing Assignment Operator
is when used for array element.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
?>
<?php
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ARRAY Operators
The same result as the previous exercise,
solved in another way.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
function DefaultValue()
{
return 'Luiz Vaz de Camões';
}
$data = [ 'title' => 'Lusiadas',
'subject' => 'An epic poem about the
Portuguese language, published in 1572.' ];
if(!isset($data['author'] ))
{
$data['author'] = DefaultValue();
}
$data['author'] ??= DefaultValue();
var_dump($data);
?>
<?php
/* - - - - - - - - - - - - - - - - - - - - - - -
ARRAY Operators
A single
USER-DEFINED
spacesharr comparison funtion
- - - - - - - - - - - - - - - - - - - - - - - */
function spacesharr($par1, $par2)
{
if(($par1 <=> $par2) == 0)
{
echo 'The two ARRAYS are the same:<br>';
var_dump($par1); echo ' = '; var_dump($par2);
echo '<br><br>';
}
elseif(($par1 <=> $par2) == -1)
{
echo 'The first ARRAY is smaller than the second:<br>';
var_dump($par1); echo ' < '; var_dump($par2);
echo '<br><br>';
}
elseif(($par1 <=> $par2) == 1)
{
echo 'The first ARRAY is bigger than the second:<br>';
var_dump($par1); echo ' > '; var_dump($par2);
echo '<br><br>';
}
}
$arr18a = [ 3, 2 ];
$arr18b = [ 2, 3 ];
$arr18c = [ [ 4, 5, 6 ], [ 7, 8, 9 ] ];
$arr18d = [ [ 7, 8, 9 ], [ 4, 5, 6 ] ];
$arr18e = [ [ 7, 8, 9 ], [ 4, 5, 6 ] ];
spacesharr($arr18a, $arr18b);
spacesharr($arr18a, $arr18c);
spacesharr($arr18c, $arr18a);
spacesharr($arr18d, $arr18a);
spacesharr($arr18c, $arr18d);
spacesharr($arr18d, $arr18e);
?>