Array unique and flip
📖 Scenario: You have a list of fruits with some duplicates. You want to find the unique fruits and then flip the list so that fruits become keys and their positions become values.
🎯 Goal: Create a PHP program that removes duplicate fruits from an array and then flips the array so that fruit names become keys and their indexes become values.
📋 What You'll Learn
Create an array called
fruits with the exact values: 'apple', 'banana', 'apple', 'orange', 'banana'Create a variable called
uniqueFruits that holds the unique values from fruitsCreate a variable called
flippedFruits that flips the keys and values of uniqueFruitsPrint the
flippedFruits array💡 Why This Matters
🌍 Real World
Removing duplicates and flipping arrays is useful when you want to quickly find the position of unique items or create lookup tables.
💼 Career
These skills are important for data cleaning, preparing data for search, and optimizing lookups in PHP web applications.
Progress0 / 4 steps