Concept Flow - Associative array creation
Start
Define key-value pairs
Create associative array
Access or use array
End
This flow shows how PHP creates an associative array by defining key-value pairs and storing them together.
<?php $person = ["name" => "Alice", "age" => 30]; print_r($person); ?>
| Step | Action | Key | Value | Array State |
|---|---|---|---|---|
| 1 | Start array creation | [] | ||
| 2 | Add key-value pair | name | Alice | ["name" => "Alice"] |
| 3 | Add key-value pair | age | 30 | ["name" => "Alice", "age" => 30] |
| 4 | Print array | ["name" => "Alice", "age" => 30] | ||
| 5 | End | ["name" => "Alice", "age" => 30] |
| Variable | Start | After 1 | After 2 | Final |
|---|---|---|---|---|
| $person | undefined | ["name" => "Alice"] | ["name" => "Alice", "age" => 30] | ["name" => "Alice", "age" => 30] |
Associative arrays store key-value pairs. Keys are unique strings or integers. Use ["key" => value] syntax to create. Access values by keys. Adding duplicate keys overwrites values.