Skip to content
PHP Logo

Is it possible to chain multiple functions in PHP to process a variable in a single line of code?

Yes, it is possible to chain multiple functions in PHP to process a variable in a single line of code using method chaining. This technique allows you to call multiple functions on the same variable in a sequential manner, with each function operating on the result of the previous one. This can help streamline your code and make it more concise and readable. Example PHP code snippet:

php
$result = strtoupper(trim("   hello world   "));
echo $result; // Output: HELLO WORLD