StepsEasy
PHP Associative Arrays - Example
Run
Reset
Destroy & Close
← Back to lesson
Code Editor
php
<?php // Indexed array $fruits = ["Apple", "Banana", "Cherry"]; // Associative array $person = [ "name" => "Alice", "age" => 25, "city" => "New York" ]; // Loop through array foreach ($person as $key => $value) { echo "$key: $value\n"; } // Array functions array_push($fruits, "Date"); sort($fruits); echo count($fruits); // 4 ?>
Result
Click "Run" to execute the code...
Loading runtime...
Ready
PHP | In-Browser Execution