PHP array twice and value at the end -


i array append string , dismiss value if value "". somehow, resulting array this: array ( [0] => test1 [1] => test2 [2] => t3 [3] => t4 [4] => t5 [5] => t6 ) test1,test2,t3,t4,t5,t6

the php code:

<?php include ('connserver.php');  if(isset($_post['submit'])) { //$query =   $updatedby = $_post['username']; $shift = $_post['shift']; $date = $_post['currdate']; $machine = $_post['machine']; $timedown = $_post['timedown']; $timeup = $_post['timeup']; $downtimetype = $_post['dttype']; $tsdowntime = $_post['troubledt']; $prodowntime = $_post['prodowntime'];  function is_notnull($var) {return !is_null($var);}  switch ($downtimetype) {     case "unscheduled":     {         $process = '-';         $description = $_post['description'];         $actiontaken = $_post['details'];         $remark = '-';         $sparepartstaken = $_post['sparepartstaken'];     }break;      case "pm":     {         $rebuiltparts = array();         for($i = 1; $i <= 6; $i++)         {             $rebuiltparts[] = $_post['rebuildparts'.$i];             $rebuiltpartsfiltered = array_filter($rebuiltparts, "is_notnull");         }         print_r(array_filter($rebuiltparts, "is_notnull"));         $process = '-';         $description = "rebuilt parts:" .implode(',',$rebuiltpartsfiltered). "";         $actiontaken = $_post['acttaken'];         $remark = '-';         $sparepartstaken = $_post['sparepartstaken'];     }break;      case "conversion":     {         $process = '-';         $description = '' .$_post['description']. '';         $actiontaken = $_post['acttaken'];         $remark = '-';         $sparepartstaken = $_post['sparepartstaken'];     }break;      case "process_issue":     {         $process = '-';         $description = '' .$_post['description']. '';         $actiontaken = $_post['acttaken'];         $remark = '-';         $sparepartstaken = $_post['sparepartstaken'];     }break;      case "others":     {     }break;      case "bi-weekly":     {}break;      default:     {} break; } print_r(implode(',',$rebuiltpartsfiltered)); /*   $process $description $actiontaken $remark $sparepartstaken */ } ?> 

searched , tried other things, got worse. don't know how express in google search. doing wrong (i believe for loop) or else? or there better ways this?

so output:

array ( [0] => test1 [1] => test2 [2] => t3 [3] => t4 [4] => t5 [5] => t6 ) test1,test2,t3,t4,t5,t6

makes perfect sense. first have code...

print_r(array_filter($rebuiltparts, "is_notnull")); 

... printing out array. generating output:

array ( [0] => test1 [1] => test2 [2] => t3 [3] => t4 [4] => t5 [5] => t6 )

then @ end have code...

print_r(implode(',',$rebuiltpartsfiltered)); 

which printing out array values comma-separated string. generating output:

test1,test2,t3,t4,t5,t6


Comments

Popular posts from this blog

gridview - Yii2 DataPorivider $totalSum for a column -

java - Suppress Jboss version details from HTTP error response -

Sass watch command compiles .scss files before full sftp upload -