Array key and value extraction
📖 Scenario: You have a list of products with their prices stored in an array. You want to separate the product names and their prices into two different arrays for easier use later.
🎯 Goal: Build a PHP script that extracts the keys (product names) and values (prices) from an associative array into two separate arrays.
📋 What You'll Learn
Create an associative array called
$products with exact entries: 'Apple' => 150, 'Banana' => 50, 'Cherry' => 200Create a variable called
$productNames to hold the keys from $productsCreate a variable called
$productPrices to hold the values from $productsPrint the
$productNames arrayPrint the
$productPrices array💡 Why This Matters
🌍 Real World
Extracting keys and values from arrays is common when working with data like product lists, user information, or settings.
💼 Career
Many jobs require handling associative arrays or dictionaries to organize and process data efficiently.
Progress0 / 4 steps