Professional Documents
Culture Documents
Sem: IF6I
Assignment No. 01 ANSWERS
// Driver Code
$number = 39;
check($number)
?>
$number1 = 12;
$number2 = 7;
$number3 = 15;
?>
<?php
// Variable example
$age = 25;
$name = "John";
Anonymous Function:
Anonymous functions, or closures, in PHP are created using the function keyword without giving
them a name. They are often used for small, one-time-use operations.
<?php
// Anonymous function example
$multiply = function ($x, $y) {
return $x * $y;
};
1. extract function:
The extract function in PHP is used to import variables into the local symbol table from
an associative array. It takes an associative array as an argument, and it creates variables
for each key-value pair in the array.
2. implode function:
The implode function is used to join array elements with a string. It takes an array as its
first argument and optionally a string as its second argument. It returns a string
containing all the array elements joined by the specified string.
3. flip function:
The flip function is used to exchange the keys with their associated values in an array. It returns a
new array where the values become keys, and the keys become values.
<?php
// Example data
$userData = array(
"name" => "John",
"age" => 25,
"city" => "New York",
"email" => "john@example.com"
);
?>
$reversedString = strrev($inputString);
echo "Reverse: $reversedString\n";
?>