0

I am getting dynamic div from the count .. in seperate box but i want that i ve fixed 6 small div inside the container.and if i get the count value 10 then it means auto pre added the div according to the dynamic value .. my code is given below.

<?php 

   echo '<div class="col-md-12 col-xs-12" style="background-color: white;height: auto;padding: 0px;border: px solid red;">';
   echo '<div class="col-md-2" style="font-weight: bold;floa:left;font-size:60px;text-align: center;border:px solid red;">';

   }
  echo '<div>';
?>

But If i get the 100 as count it look like:

0 1 0 0 but i want to fix 6 divs starting with the prefix 0.

1 Answer 1

3

You can use the array_pad function to pad the array with 0 to the desired length. Try the code below.

<?php 
$count=10;
 $array = array_pad(str_split($count), -5, 0);
//print_r($array);exit;
   echo '<div class="col-md-12 col-xs-12" style="background-color: white;height: auto;padding: 0px;border: px solid red;">';
   echo '<div class="col-md-2" style="font-weight: bold;floa:left;font-size:60px;text-align: center;border:px solid red;">';
  echo '<div class="col-md-12" style="border:1px solid green;">0</div>'; 
    echo '</div>';
   foreach($array as $value){
   echo '<div class="col-md-2" style="font-weight: bold;floa:left;font-size:60px;text-align: center;border:px solid red;">';
 echo '<div class="col-md-12" style="border:1px solid green;">'. $value.'</div>';
   echo '</div>';
   }
  echo '<div>';
?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.