Monday, 6 July 2015

PHP: Add duplicate elements to an array

<?php
$columnsArr = array('','');
$colArr = array(2=>'DIABETES WITH ACUTE COMPLICATIONS'
,5=>'DIABETES WITH CHRONIC COMPLICATIONS'
,8=>'DIABETES'
,11=>'MALNUTRITION'
,14=>'OBESITY'
,17=>'RHEUMATOID'
,20=>'DRUG/ALCOHOL'
,23=>'PSYCH'
,26=>'NEURO'
,29=>'CARDIAC DISEASE'
,32=>'VASCULAR DISEASE'
,35=>'LUNG DISEASE'
,38=>'KIDNEY DISEASES');
foreach($colArr as $key=>$val){
  $columnsArr1 = array_fill($key,3, $val);
 $columnsArr = array_merge($columnsArr,$columnsArr1); 
}
echo "<pre>";
  print_r($columnsArr);
echo "</pre>";

?>

0 comments:

Post a Comment