markuszeller

getPhotoHtml

Jul 25th, 2022 (edited)
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.52 KB | None | 0 0
  1. <?php // https://stackoverflow.com/questions/73105094/should-i-call-this-function-or-echo-the-variable
  2.  
  3. function getPhotoHtml(array $person = []): string
  4. {
  5.     $path = 'photos';
  6.  
  7.     if (empty($person['photo_url']) || !file_exists("$path/" . basename($person['photo_url']))) {
  8.         return "<img src='$path/no_photo_available.png' alt='no photo available'>";
  9.     }
  10.  
  11.     return "<img src='$path/{$person['photo_url']}' alt='{$person['name']}'>";
  12. }
  13.  
  14. foreach($persons as $person) {
  15.     echo getPhotoHtml($person);
  16. }
Add Comment
Please, Sign In to add comment