1. What is array? How to store data in array?
Ans:
In PHP, an array is a special variable that can store multiple values in one single
variable.
Instead of creating many variables like $a1, $a2, $a3, you can use one array like $a =
array(10, 20, 30);.
Arrays can store numbers, strings, or both.
Types:
2. Write a program to create associative array in PHP.
Ans:
3. Define function. How to define user defined function in PHP? Give example.
Ans:
Types:
4. Write PHP script to sort any five numbers using array function.
5. String functions
6. Explain indexed and associative array
7.
8.
9. Multidimensional array
10.
11. Strrev()
Ans:
It takes a string as input and returns the reversed version of that string.
It is commonly used to check for palindromes or manipulate string patterns.
The function does not change the original string; it returns a new reversed string.
If the input string is "Hello", then strrev("Hello") will return "olleH".
• <?php echo strrev("Information Technology"); ?>
12. Strops()
Ans:
It takes two arguments: the main string and the substring to search for.
It returns the numeric position of the first match (index starts from 0).
If the substring is not found, it returns false.
It is case-sensitive. "Hello" and "hello" will be treated differently.
Often used to check if a word or character exists in a string.
For example, strpos("Good Morning", "Morning") will return 5 because "Morning"
starts at index 5.
13. Str_word_count
14. Str_replace()
Hello PHP
15. Strlen()
16. Strtoupper()
17. Array_flip(array):
18. Anonymous function
Ans:
An anonymous function is a function without a name.
It is assigned to a variable and called using that variable.
It is often used for callback functions or short logic blocks.
Can be passed as an argument to another function.
This function is also called closure or lambda function.
Syntax:
$var=function ($arg1, $arg2) { return $val; };
19. Variable function
Ans:
A variable function is calling a function using a variable that stores its name.
The function must be defined before the variable is used to call it.
Useful in dynamic programming where function calls depend on conditions.
The variable must exactly match the function name.
Syntax: