answersLogoWhite

0


Best Answer

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

15y ago
This answer is:
User Avatar

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 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'.


When you need to obtain the ASCII value of a character which function apply in PHP?

ord() is the function you need. echo ord(' '); Would output the number 32.

Related questions

How do you echo the return value of a function?

echo function();


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 esac for UNIX?

'esac' is the end identifier for the 'case' selection statement. For example, case $i in Y|y) echo said yes ;; N|n) echo said no ;; *) echo $i is a bad answer esac


What animal's call has no echo?

A wolf's howl doesn't have an echo because of the frequency. Also a duck's quack doesn't echo (Actually a duck's quack will echo. Google Mythbusters - they did research on this.)


What do you call a sound that bouces back to you?

That would be an echo.


Why php Echo not printing output with parenthesis?

echo will not return output when using parenthesis because echo is not a function like print. echo is a language construct. The benefit to using echo over the print function is speed, plus you can separate data types using comma's rather than periods.Example:echo 'This is a string ' , $variable , ' ending string';is the same (but faster) as:print('This is a sting' . $variable . ' ending string');


What is about php function?

A php function is coding that can be called multiple times to repeat a task. function add_numbers($num1,$num2) { return $num1 + $num2; } this would add two numbers together when called, so when you call $x = add_numbers(1,3); echo $x; //displays 4


How do you call repeated echoes?

Continuously repeating echoes in a room are known as reverberation.Where the echo is distinct, it is just an echo


What do you call the repetition of sound caused by the reflection of sound waves?

echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo


Write a program which uses employs recursion?

// recursive implementation of factorial function long factorial(const int n) { if(n <= 1) { return 1L; } return n * factorial(n-1); } @echo off echo RECURSE.BAT echo This demonstrates recursion echo To run this, save this into a document on your desktop named RECURSE.BAT then double click call :func 5 echo All done. pause goto :eof rem Functions begin here :func rem Variables in this language are globally scoped. SETLOCAL makes the variable scope local. setlocal set /a nextlevel=%1 - 1 echo Start Level=%1 - Next level= rem Here is our recursive call. Note that we only call recursively if the next level is greater than or equal to 1 ifgeq 1 call :func echo End Level=%1 endlocal goto :eof