Update a bakery ticket
Before you start this intermediate track
Variables, function calls, and key-value arrays. These examples run as small scripts.
Guided code reading and debugging. Runnable coding challenges are available in JavaScript, Python, and SQL.
Understand it, then try it.
A bakery ticket uses an associative array so each value has a meaningful key. Assigning through an existing key replaces that entry without adding another item. Empty brackets would append a new entry instead. count reports the number of entries, which is useful for checking whether an update changed the ticket structure.
<?php$order = ["bread" => "rye", "sliced" => true];$order["bread"] = "sourdough";echo $order["bread"], "\n";echo count($order), "\n";Each mission is a complete independent PHP 8 or later command-line script, including the opening <?php tag. Save as quest.php and run php quest.php. Output is plain text; no web server is required.
Track the values line by line. Predict the result before running this example in your own editor.