将循环值存储在数组中

I want to store all value in a array and get out from the loop is it possible?

<?php
    $a=array('a', 'b', 'c');
    foreach($a as $b)
    {
        for($i=0; $i<count($a); $i++)
        {
            $c = array();
            $c[$i] = $b;     
        }

        print_r($c);
    }
?>

I made a mistake the array variable $c=array() should be out side of loop

<?php

   $a=array('a','b','c');

   $c=array();
   // for loop
   for($i=0;$i<count($a);$i++){
       $c[$i]=$a[$i];
   }
   // forEach loop
   foreach ($a as $b){
         $c[]=$b;
   }
   // while loop
   $x=0;
   while($x<count($a)){
          $c[$x]=$a[$x];
          $x++;
   }

  print_r($c);
?>

Can you try this, Moved $c = array(); from inside forloop into outside the forloop.

<?php
   $a=array('a','b','c');
    foreach($a as $b){
        $c = array();
        for($i=0;$i<count($a);$i++){                
            $c[$i]=$b;
        }
        print_r($c);
    }
?>

Why you are defining array at each iteration?

<?php
$a=array('a','b','c');
foreach($a as $b){
    $c=array();
    for($i=0;$i<count($a);$i++){
    $c[$i]=$b;     
}
print_r($c);
}
?>