Creating a checklist with ACF and I cannot figure out how to add all iterations to an array that I’m creating


Ok so I have this code on my website and I am trying to understand fully what is happening.

            <?php if( have_rows('comparison_chart') ): ?>
                <?php $feature_matrix = array(); ?>
                <?php $available_tiers = array(
                    'Learning Experience Platform' => 'learning_experience_platform', 
                    'Learning Management System' => 'learning_management_system'
                ); ?>
                <?php while( have_rows('comparison_chart') ): the_row(); ?>
                    <?php $feature = get_sub_field('feature'); ?>
                    <?php $tiers = get_sub_field('tiers'); ?>
                    <?php $info = get_sub_field('feature_info'); ?>
                    <?php foreach ($available_tiers as $tier => $slug) {
                        if (in_array($tier, $tiers)){
                            $feature_matrix['Tiers'][$tier][] = $feature;

                    } ?>
                    <?php $feature_matrix['Features'][$feature] = $tiers; ?>
                <?php endwhile; ?>
            <?php endif; ?>

The reason I am trying to understand what is going on is because I know there is an array created called feature_matrix and it looks like it’s adding these sub field to the array and what I need to do is add the feature_info sub field to that array also so I can pull it for each array and use it on the website. Below the code there is this code which pulls each feature and tier.

                 <?php foreach ($feature_matrix['Features'] as $feature => $tier): ?>
                        <?php $tiers = $feature_matrix['Features'][$feature]; ?>
                        <div class="row desktop-features">
                            <div class="col-md-6 features">
                                <?php echo $feature; ?><span class="caret">&#9013;</span>
                            <?php foreach ($available_tiers as $tier => $slug): ?>
                                <div class="col-xs-12 col-md-3 marker">
                                    <?php if (in_array($tier, $tiers)): ?>
                                        <i class="icon-check2"></i>
                                    <?php endif; ?>
                            <?php endforeach; ?>
                            <div class="col-xs-12 col-md-6 feature-info">
                                <?php echo $info; ?>
                            <div class="clearfix"></div>
                    <?php endforeach; ?>

You can see I am trying to pull the info variable but it keeps pulling only the last iteration of the array. How can I get it to pull each iteration of the array for each single one?

Hexen 1 year 2020-07-23T15:11:10-05:00 0 Answers 46 views 0

Leave an answer