Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php // https://stackoverflow.com/questions/73105094/should-i-call-this-function-or-echo-the-variable
- function getPhotoHtml(array $person = []): string
- {
- $path = 'photos';
- if (empty($person['photo_url']) || !file_exists("$path/" . basename($person['photo_url']))) {
- return "<img src='$path/no_photo_available.png' alt='no photo available'>";
- }
- return "<img src='$path/{$person['photo_url']}' alt='{$person['name']}'>";
- }
- foreach($persons as $person) {
- echo getPhotoHtml($person);
- }
Add Comment
Please, Sign In to add comment