H
H
Harvey Specter2020-04-20 15:21:28
PHP
Harvey Specter, 2020-04-20 15:21:28

What is missing in the PHP code to display the full html code?

Hi, please tell me, I'm trying to write an html output function in php, without knowing it at all.

// Получаем массив от плагина картинок
 $our_guests_images = acf_photo_gallery('ourguests_gosti', 143);

        function guest_single($number, $photo_id)
        {
     // Вывожу нужные элементы массива в отдельные переменные для удобства
            $link_out = $our_guests_images["$photo_id"]["url"];
            $img_out = $our_guests_images["$photo_id"]["full_image_url"];
            $title_out = $our_guests_images["$photo_id"]["title"];
     // Переменная с конечным кодом, который нужно вывести
            $echo_content = '
            <a href="'.$link_out.'" class="guest-photo guest-photo--'.$number.'" target="_blank" >
                <img src="'.$img_out.'" alt="">
                <div class="guest-photo__link">'.$title_out.'</div>
            </a>';
            return $echo_content;
        }


When used in a template, for example: echo guest_single(1, 1); Only the markup from $echo_content is displayed, but without the necessary variables $link_out, $img_out, $title_out, they are empty instead, the effect is the same as if there is not enough echo for them, but I don’t know how to apply it, when using echo an error occurs in the variable.
Someone knows what's the problem? Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
FanatPHP, 2020-04-20
@HarviSpecter

inside the function a separate scope of variables
is therefore

function guest_single($number, $photo_id, $our_guests_images)

well, or call acf_photo_gallery inside

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question