fork download
  1. <?php
  2. $i = true;
  3. $array = array('red');
  4. foreach($array as $key => & $value) {
  5. echo $value . '<br />';
  6. if ($i === true) {
  7. $a1= $array;
  8. $a2= array($value);
  9. $result=array_diff($a1,$a2);
  10. print_r($result);
  11.  
  12. $others = array('white', 'yellow');
  13. if(!empty($result)){
  14. $array = array_merge($others,$result);
  15. } else {
  16. $array = array_merge($others,$array);
  17. }
  18. }
  19. $i = false;
  20. }
Success #stdin #stdout 0s 52488KB
stdin
Standard input is empty
stdout
red<br />Array
(
)