PHP performance

Just a short question.

What is more performant to write:

<?php if ($page->stickyCtaKind() == 'default') : ?>
show default
    <?php endif ?>

    <?php if ($page->stickyCtaKind() == 'basic') : ?>
show number basic
    <?php endif ?>

    <?php if ($page->stickyCtaKind() == 'pro') : ?>
show number pro
    <?php endif ?>


    <?php $stickyCtaKind = $page->stickyCtaKind()?>

    <?php if ($stickyCtaKind == 'default') : ?>
        show default
        <?php endif ?>

Is $page->stickyCtaKind() similiar to getElementById? I mean if yes, the second way would be more performant.


A variable stores data in memory. So it definitely makes sense to store a query that you use more than once in a variable.

1 Like