I have been trying to loop nested foreach
loops but the problem is first foreach
loop records repeating as the count of second foreach
loop
first array is coming from mysql
data and second array I have wrote below, In my case i want to loop the color presets in second array with first foreach
loop results. I'm not much good in arrays please help me to solve this issue.
here is the second array and code :
$colors = array (
0 => array ("id"=> 0, "dark" => "#16a085", "light" => "#1ABC9C"),
1 => array ("id"=> 1, "dark" => "#2980B9", "light" => "#3498DB "),
);
$unique = array_unique($colors, SORT_REGULAR);
foreach ($skill as $skilldata) {
foreach ($unique as $key => $val) {
<div class="skillbar clearfix " data-percent="<?php echo $skilldata['js_skill_perc'].'%'; ?>">
<div class="skillbar-title" style="background: <?php echo $val['dark']?>;">
<span><?php echo $skilldata['js_skill_title']; ?></span></div>
<div class="skillbar-bar" style="background-color: <?php echo $val['light']?>; width: <?php echo $skilldata['js_skill_perc'].'%'; ?>;"></div>
<div class="skill-bar-percent"><?php echo $skilldata['js_skill_perc'].'%'; ?></div>
</div>
<?php }} ?>
Output should be like : HTML5 (green) PHP(blue) and SEO (green) but this is how output looks like:
$skill
? Your question is not very clear... What is the output you wanted? – Alan Machado Oct 2 '15 at 11:00mysql
data(HTML, PHP, SEO) – Sahan Perera Oct 2 '15 at 11:01