answersLogoWhite

0

Of course it is possible to call a PHP-function inside an echo statement. The function will be executed and returns a value. This value then is used in the echo statement.

For example:

echo "Ferengi-Rule #1: ", ferengi_rule(1), "\n";

echo "Random: ", ferengi_rule(0), "\n";

function ferengi_rule($number)

{

$rules = array(

1 => "Once you have their money, never give it back.",

2 => "You can't cheat an honest customer, but it never hurts to try.",

3 => "Never buy anything for more than is absolutely necessary.",

4 => "Sex and profit are the two things that never last long enough."

// ...

);

if( isset($rules[$number]) )

{

return $rules[$number];

}

else

{

return array_rand($rules);

}

}

User Avatar

Wiki User

16y ago

Still curious? Ask our experts.

Chat with our AI personalities

FranFran
I've made my fair share of mistakes, and if I can help you avoid a few, I'd sure like to try.
Chat with Fran
DevinDevin
I've poured enough drinks to know that people don't always want advice—they just want to talk.
Chat with Devin
EzraEzra
Faith is not about having all the answers, but learning to ask the right questions.
Chat with Ezra

Add your answer:

Earn +20 pts
Q: Can you call a function inside an echo statement in PHP?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Basic Math

Program for palindrome in php?

You could use a function like this:function isPalindrome($string) {$string = strtolower($string);return (strrev($string) == $string) ? true : false;}and then to check a palindrome call an if statement like so:if(isPalindrome($test)) {echo $test.' is a palindrome';}else {echo $test.' is not a palindrome';}


How do you use a function with a button in PHP?

A simple function call <html> <body> <?php if(isset($_POST['button'])) { setValue(); // Function is called } function setValue() { echo "<br>The button property to call PHP function works"; // Your code here } ?> <input type="submit" name="button" onclick=<?php $_SERVER['PHP_SELF']; ?> /> </body> </head>


How to display a variable in PHP using echo or print statements?

displaying a variable in php using echo statement? <?php $name="ram"; //declaring and defining the variable echo "$name"; //printing the variable using echo command ?>


What is the difference between echo and print statement?

Well, darling, an echo statement is a language construct in PHP that displays output, while a print statement is a language construct that also displays output but returns a value. So, in simpler terms, echo is faster and more commonly used, while print is slower but can be used in expressions. Hope that clears things up for you!


What is the difference between echo and print and printf in PHP?

The print function is slightly more dynamic than the echo function by returning a value, and the echo function is slightly (very slightly) faster. The printf function inserts dynamic variables/whatever into wherever you want with special delimiters, such as %s, or %d. For example, printf('There is a difference between %s and %s', 'good', 'evil') would return 'There is a difference between good and evil'.