Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,859 questions

51,780 answers

573 users

How to suppress any output from a function in PHP

1 Answer

0 votes
function example($i) {
  echo "example() function: " . $i . "\n";
  
  return true;
}

$rv  = false;
$rv = example(3524); // output "example() function: 3524"
echo "A rv = " . $rv . "\n"; // return true;

$rv  = false;
// ob = output buffering
ob_start();
$rv = example(86903); // get return value without output
echo "B1 rv = " . $rv . "\n";
ob_end_clean();
echo "B2 rv = " . $rv . "\n"; // return true;



/*
run:

example() function: 3524
A rv = 1
B2 rv = 1

*/

 



answered Jul 22, 2025 by avibootz
edited Jul 22, 2025 by avibootz
...