Trying to understand PHP code

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>
									</div>
									<?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; ?>
										</div>
									<?php endforeach; ?>
								</div>
									<div class="col-xs-12 col-md-6 feature-info">
										<?php echo $info; ?>
									</div>
									<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?

First thing, the constant open and closing of Php needs to go.

Thank you for suggestions! After doing that do you know how I would make to pull info variable when each iterration of array go through foreach on bottom portion code?

Sponsor our Newsletter | Privacy Policy | Terms of Service