Loading Depth Study
Preparing your workspace
PHP arrays can represent ordered lists as well as key-value collections.
PHP arrays are flexible structures that can be used as indexed lists or associative maps. Indexed arrays use numeric keys, while associative arrays use named keys. Arrays can also contain other arrays, making nested structures possible. Common functions such as count, array_map, array_filter, and foreach help process collections. Understanding arrays is essential because PHP applications constantly work with request data, database results, configuration, and API responses.
A course can be represented as an associative array, while a list of courses can be represented as an indexed array of course records.
<?php
$student = [
'name' => 'Aman',
'score' => 92,
'course' => 'PHP'
];
$courses = ['HTML', 'CSS', 'PHP'];
foreach ($courses as $course) {
echo $course . PHP_EOL;
}The script prints HTML, CSS, and PHP on separate lines.