PHP - Array Functions
What is the output of the following PHP code?
$name = "Alice";
$age = 30;
$arr = compact('name', 'age');
print_r($arr);
$name = "Alice";
$age = 30;
$arr = compact('name', 'age');
print_r($arr);
compact behaviorcompact function creates an array where keys are the variable names as strings and values are the current values of those variables.$name and $age have values "Alice" and 30, so the array will be ['name' => 'Alice', 'age' => 30].15+ quiz questions · All difficulty levels · Free
Free Signup - Practice All Questions