String Functions — PHP Technical Interview Questions & Answers
String Functions
String Functions
- String Functions is a PHP topic. In plain words you use it for function add($a, $b) in a marks helper. Don’t start with a slogan — start with that picture.
- Smallest example: function name($x) { return $x; }. Type it, run it, and say what you see. If you can do that from memory, you know String Functions.
- From the example next to this theory: String Functions — typed params and return types make PHP APIs clearer.
- Trap: no return so the caller gets null. Fix that before you talk about advanced PHP.
- Viva: what is String Functions? Then show function name($x) { return $x; }. Then name the trap.
Technical Interview Tip: What is String Functions? Show this: function name($x) { return $x; }. Trap: no return so the caller gets null.
Code Examples for String Functions
String Functions — working example
<?php
function greet(string $name, int $n = 1): string {
return str_repeat("Hi $name! ", $n);
}
echo greet("Asha");
echo greet("Dev", 2);String Functions — typed params and return types make PHP APIs clearer.
How to Explain String Functions to an Interviewer
What is String Functions?
Used for function add($a, $b) a marks helper Not just the heading
Give one small example of String Functions.
function name($x) { return $x; } String Functions — typed params and return types make PHP APIs clearer
What mistake do beginners make with String Functions?
no return so the caller gets null Show the fix
Where do you use String Functions?
a marks helper function add($a, $b)