Created
August 11, 2015 15:56
-
-
Save travisfont/042e43651d9ddd447d48 to your computer and use it in GitHub Desktop.
They said it's impossible in PHP, so here you go.. function's and condition statements inside a Heredoc in PHP. it's possible!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $result = function ($arg1 = false, $arg2 = false) | |
| { | |
| return 'function works'; | |
| }; | |
| $if = function ($condition, $true, $false) { return $condition ? $true : $false; }; | |
| // - #################################### | |
| $set = <<<HTML | |
| bal bal dasdas<br/> | |
| sdadssa | |
| HTML; | |
| $empty = <<<HTML | |
| data is empty | |
| HTML; | |
| $var = 'setting the variable'; | |
| // - #################################### | |
| echo <<<HTML | |
| <div style="padding-left: 34px; padding-bottom: 18px;font-size: 52px; color: #B0C218;"> | |
| {$if(isset($var), $set, $empty)} | |
| <br/><br/> | |
| {$result()} | |
| </div> | |
| HTML; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment