Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP shortening, echo variable if defined

Tags:

php

Is there any way to shorten this code ?

<?= isset($email)?$email:''; ?>

I feel it's kind of stupid to repeat $email. I've tried

<?= isset($email)?:''; ?>

But it echoes the boolean coming from isset instead.

like image 237
superzamp Avatar asked Sep 08 '26 07:09

superzamp


1 Answers

<?= isset($email)?$email:''; ?> // is the shortest way to do it.
like image 82
Mehdi Karamosly Avatar answered Sep 11 '26 15:09

Mehdi Karamosly



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!