Arrays

• Way of ordering data by associating values to keys
• Unique keys are associated with a single value, or set of values
• Arrays can be nested, so that a value in one array actually represents a complete other array (multi-dimensional arrays)

Creating Arrays

INDEXED NUMERICALLY (INDEXED ARRAY)

o EX: $x = array(‘a’, ‘b’, ‘c’);
o EX: $x = [‘a’, ‘b’, ‘c’];
o EX: $x = array(0 => ‘a’, 1 => ‘b’, 2 => ‘c’);
o EX: $x = [0 => ‘a’, 1 => ‘b’, 2 => ‘c’];

INDEXED WITH STRINGS (ASSOCIATIVE ARRAY)

$x = array(
‘XML’ => ‘eXtensible Markup Language’
);
$x = [
‘XML’ => ‘eXtensible Markup Language’
];

Filling Arrays

• range() CREATES AN ARRAY WITH VALUES FROM AN INTERVAL

o DEFAULT STEP IS “1”

o EX: $x = range(1.2, 4.1) // == array(1.2, 2.2, 3.2)

Share

Leave a Reply

Your email address will not be published. Required fields are marked *