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.
Predict the result.
What two lines are printed for the updated ticket?
<?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.
Review the lesson
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.