Module 2 – PHP Fundamentals
Lesson
Arrays
Indexed and associative
Arrays are created with [] or array(). Functions: count, in_array, array_push, array_map, array_filter. Multidimensional arrays represent data tables. JSON encode/decode often exchanges arrays with the frontend.
Sorting
sort, rsort, asort, ksort – choose based on whether keys matter.
<?php
$ocene = [9, 10, 8];
$prosek = array_sum($ocene) / count($ocene);
$filtrirane = array_filter($ocene, fn($o) => $o >= 9);Example variation
Extend the lesson example: add another variable, change the loop boundary or branching, and observe the output. Deliberately introduce an error (e.g. an undefined variable) to see the PHP message – then fix it.
