How to create an array of names with one statement

$names = array('Ted Lewis', 'Sue Jones', 'Ray Thomas');

How to create an array with multiple statements

$names = array();
$names[0] = 'Ted Lewis';
$names[1] = 'Sue Jones';
$names[2] = 'Ray Thomas';

How to create an array of discounts with one statement

$discounts = array(0, 5, 10, 15);

How to create an array of discounts with multiple statements

$discounts = array();
$discounts[0] = 0;
$discounts[1] = 5;
$discounts[2] = 10;
$discounts[3] = 15;

How to use the print_r() function to view an array’s indexes and values

print_r($names); // Output: Array ( [0] => Ted Lewis [1] => Sue Jones [2] => Ray Thomas )

Array ( [0] => Ted Lewis [1] => Sue Jones [2] => Ray Thomas )

How to define a constant for an array (PHP 7.0 and later)

define('MONTHS', array('Jan', 'Feb', 'Mar'));

Back