<?php
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Any ordered map associated with values and keys
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
?>
COMMON UNIDIMENSIONAL ARRAY | ||
KEY TYPE | FIRST | OTHER |
INTEGER | ALWAYS ZERO | POSITIVE AND SEQUENTIAL |
KEYS NOT PROVIDED | ||
VALUE TYPES | FIRST | OTHER |
STRING | ANY OF THE THREE TYPES | ANY OF THE THREE TYPES |
INTEGER | ||
FLOAT | ||
ed48 |
<?php
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SOME VALID VARIABLE EXAMPLES
COMMON UNIDIMENSIONAL
USER-DEFINED ARRAY DEFINITION
Before PHP 5.4.0 there was only
one way to defining ARRAYS:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
$arr_O = array( mix $var1, mix $var2, ... mix $varN );
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Since PHP 5.4.0 there has been
a new way to define:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
$arr_N = [ mix $var1, mix $var2, ... mix $varN ];
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
The two ways, then, to live together,
can be used interchangeably,
until desire to the contrary.
The choice of which mode to use will depend,
therefore, on the PHP version
that will be used by the programmer.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
?>
<?php
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SOME VALID VARIABLE EXAMPLES
COMMON UNIDIMENSIONAL
USER-DEFINED ARRAY DEFINITION
$arr_O = array( mix $var1,
mix $var2, ...,
... mix $varN );
$arr_N = [ mix $var1,
mix $var2, ...,
... mix $varN ];
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
$arr01a = array(2, 8, 18, 32, 32, 18, 8);
$arr01b = [ 2, 8, 18, 32, 32, 18, 8 ];
$arr01c = [ 2, 8, '18', 32, 'THIRTY-TWO', "eighteen", 8 ];
$arr01d = [ 299792458, 6.67428E-11, 'c', "G" ];
$arr01e = [01023, 0B0011, 0x20b ];
?>
UNIDIMENSIONAL ASSOCIATIVE ARRAY | ||
KEY TYPES | FIRST | OTHER |
STRING | SINCE IS CONSIDERED VALID | SINCE IS CONSIDERED VALID AND NOT REPEATED |
INTEGER | NOT NECESSARILY EQUIVALENT TO ZERO |
DO NOT NEED TO BE SEQUENTIAL, ONLY DIFFERENTS |
ONLY ONE KEY TYPE IS ACCEPTED | ||
VALUE TYPES | FIRST | OTHER |
STRING | ANY OF THE THREE TYPES | ANY OF THE THREE TYPES |
INTEGER | ||
FLOAT | ||
ed48 |
<?php
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SOME VALID VARIABLE EXAMPLES
UNIDIMENSIONAL ASSOCIATIVE
USER-DEFINED ARRAY DEFINITION
Before PHP 5.4.0 there was only
one way to defining ARRAYS:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
$arr_O = array( mix $key1 => mix $var1,
mix $key2 => mix $var2,
mix $keyN => mix $varN );
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Since PHP 5.4.0 there has been
a new way to define:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
$arr_N = [ mix $key1 => mix $var1,
mix $key2 => mix $var2,
mix $keyN => mix $varN ];
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
The two ways, then, to live together,
can be used interchangeably,
until desire to the contrary.
The choice of which mode to use will depend,
therefore, on the PHP version
that will be used by the programmer.
In this tutorial,
we will always use the most
current version of PHP; therefore,
we will employ the most recent definition.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
?>
<?php
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SOME VALID VARIABLE EXAMPLES
UNIDIMENSIONAL ASSOCIATIVE
USER-DEFINED ARRAY DEFINITION
$arr_O = array( mix $key1 => mix $var1,
mix $key2 => mix $var2,
mix $keyN => mix $varN );
$arr_N = [ mix $key1 => mix $var1,
mix $key2 => mix $var2,
mix $keyN => mix $varN ];
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
$arr02a = array('K' => 2,
"L" => 8,
"M" => 18,
"N" => 32,
"O" => 32,
"P" => 18,
"Q" => 8 );
$arr02b = [ 'K' => 2,
"L" => 8,
"M" => 18,
"N" => 32,
"O" => 32,
"P" => 18,
"Q" => 8 ];
$arr02c = [ 'THIRTY-TWO' => 32, "EIGHTEEN" => 18 ];
$arr02d = [ 'c' => 299792458, 'G' => 6.67428E-11 ];
$arr02e = [ 2 => 'two', 4 => 'four' ];
?>
COMMON MULTIDIMENSIONAL ARRAY | ||
KEY TYPES | FIRST | OTHER |
INTEGER | ALWAYS ZERO | POSITIVE AND SEQUENTIAL |
VALUE TYPES | FIRST | OTHER |
STRING | ANY OF THE FOUR TYPES | ANY OF THE FOUR TYPES |
INTEGER | ||
FLOAT | ||
ARRAY | AT LEAST ONE MUST HAVE THIS VALUE TYPE | |
ed48 |
<?php
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SOME VALID VARIABLE EXAMPLES
COMMON MULTIDIMENSIONAL
USER-DEFINED ARRAY DEFINITION
Before PHP 5.4.0 there was only
one way to defining ARRAYS:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
$arr_O = array( mix $var1, mix $var2, ... mix $varN );
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Since PHP 5.4.0 there has been
a new way to define:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
$arr_N = [ mix $var1, mix $var2, ... mix $varN ];
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
The two ways, then, to live together,
can be used interchangeably,
until desire to the contrary.
The choice of which mode to use will depend,
therefore, on the PHP version
that will be used by the programmer.
In this tutorial,
we will always use the most
current version of PHP; therefore,
we will employ the most recent definition.
AT LEAST ONE OF THE VALUE TYPES MUST BE AN ARRAY
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
?>
<?php
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SOME VALID VARIABLE EXAMPLES
COMMON MULTIDIMENSIONAL
USER-DEFINED ARRAY DEFINITION
$arr_O = array( mix $var1, mix $var2, ... mix $varN );
$arr_N = [ mix $var1, mix $var2, ... mix $varN ];
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
$arr03a = array(2, 8, 18, 32, array (32, 18, 8));
$arr03b = [ 2, 8, 18, 32, [ 32, 18, 8 ] ];
$arr03c = [ 2, 8, '18', 32, [ 'THIRTY-TWO', "eighteen", 8 ] ];
$arr03d = [ 299792458, 6.67428E-11, [ 'c', "G" ] ];
$arr03e = ['01023', '0B0011', '0x20b',
['octal', 'binary', 'hexadecimal' ] ];
$arr03f = ["Countries", "continentes",
["Brasil", "Portugal", "Japan"],
["South America", "Europe", "Asia"] ];
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
?>
ASSOCIATIVE MULTIDIMENSIONAL ARRAY | ||
KEY TYPES | FIRST | OTHER |
STRING | SINCE IS CONSIDERED VALID | SINCE IS CONSIDERED VALID AND NOT REPEATED |
INTEGER | NOT NECESSARILY EQUIVALENT TO ZERO |
DO NOT NEED TO BE SEQUENTIAL, ONLY DIFFERENTS |
BOTH KEY TYPES ARE ACCEPTED | ||
VALUE TYPES | FIRST | OTHER |
STRING | ANY OF THE FOUR TYPES | ANY OF THE FOUR TYPES |
INTEGER | ||
FLOAT | ||
ARRAY | AT LEAST ONE MUST HAVE THIS VALUE TYPE | |
ed48 |
<?php
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SOME VALID VARIABLE EXAMPLES
ASSOCIATIVE MULTIDIMENSIONAL
USER-DEFINED ARRAY DEFINITION
Before PHP 5.4.0 there was only
one way to defining ARRAYS:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
$arr_O = array( mix $key1 => mix $var1,
mix $key2 => mix $var2,
mix $keyN => mix $varN );
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Since PHP 5.4.0 there has been
a new way to define:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
$arr_N = [ mix $key1 => mix $var1,
mix $key2 => mix $var2,
mix $keyN => mix $varN ];
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
The two ways, then, to live together,
can be used interchangeably,
until desire to the contrary.
The choice of which mode to use will depend,
therefore, on the PHP version
that will be used by the programmer.
In this tutorial,
we will always use the most
current version of PHP; therefore,
we will employ the most recent definition.
AT LEAST ONE OF THE VALUE TYPES MUST BE AN ARRAY
EVENTUALLY, if a FLOAT type is used as a KEY,
it will be converted to INTEGER.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
?>
<?php
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SOME VALID VARIABLE EXAMPLES
ASSOCIATIVE MULTIDIMENSIONAL
USER-DEFINED ARRAY DEFINITION
$arr_O = array( mix $key1 => mix $var1,
mix $key2 => mix $var2,
mix $keyN => mix $varN );
$arr_N = [ mix $key1 => mix $var1,
mix $key2 => mix $var2,
mix $keyN => mix $varN ];
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
$arr14 = array ("Countries" => array("Brasil",
"Portugal",
"Japan"),
"Continents" => array ("South America",
"Europe",
"Asia"));
$arr14 = [ "Countries" => [ "Brasil",
"Portugal",
"Japan" ],
"Continents" => ["South America",
"Europe",
"Asia"]];
$arr15 =
[ "Countries" => [ 'BRA' => "Brasil",
'POR' => "Portugal",
'JPN' => "Japan" ],
"Continents" => ['SA' => "South America",
'EU' => "Europe",
'AS' => "Asia"]];
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
?>
<?php
$str05 = 'John Doe';
$arr05 = [ 'name' => 'Me', 'address' => 'Here' ];
$arr05['user'] ??= $str05;
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
If you run this exercise as is,
nothing will be displayed,
as there is no function to print the result.
This will be seen shortly.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
?>
<?php
$arr06a = [ 'red', 'green'];
$arr06b = ['blue', 'yellow', 'black'];
$arr06 = [...$arr06a, 'blue', 'yellow', 'black'];
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
If you run this exercise as is,
nothing will be displayed,
as there is no function to print the result.
This will be seen shortly.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
?>