Complete the code to create an array from variables using the compact function.
<?php $name = "Alice"; $age = 25; $data = [1]("name", "age"); print_r($data); ?>
The compact function creates an array from variables given their names as strings.
Complete the code to extract variables from the array using the extract function.
<?php $data = ['city' => 'Paris', 'country' => 'France']; [1]($data); echo $city . ', ' . $country; ?>
The extract function imports variables from an array into the current symbol table.
Fix the error in the code by choosing the correct function to create an array from variables.
<?php $fruit = "apple"; $color = "red"; $info = [1]("fruit", "color"); print_r($info); ?>
The compact function correctly creates an array from variable names. Using extract here would cause an error.
Fill both blanks to create an array from variables and then extract them back.
<?php $animal = "dog"; $legs = 4; $data = [1]("animal", "legs"); [2]($data); echo $animal . ' has ' . $legs . ' legs.'; ?>
First, compact creates an array from variables. Then, extract imports variables from that array.
Fill both blanks to create an array from variables, extract them, and print a sentence.
<?php $brand = "Toyota"; $model = "Corolla"; $year = 2020; $data = [1]("brand", "model", "year"); [2]($data); echo "Car: " . $brand . " " . $model . " (" . $year . ")"; ?>
Use compact to create the array, extract to import variables from that array.