php - How should I separate the value of array as even, odd? -


question

currently output coming pnl testing 1,10,pnl testing 2,55, want manipulate , store in 2 different variables string like:

$teams = "pnl testing 1, pnl testing 2";

$amount = "10, 55";

please let me know how should split in above format.

code

while ($row1 = mysql_fetch_assoc($result)){     $profit = 0;     $total = 0;     $loss = 0;     $final_array = '';     $final_array .= $teams = $row1['t_name'].",";     $teams = explode(",", $teams);      $transact_money = $row1['pnl_amount'];     $pnl_results = $row1['pnl'];      $transact_money = explode("|", $transact_money);     $pnl_results = explode("|", $pnl_results);     for($i=0; $i<count($transact_money); $i++){         if($pnl_results[$i]=='profit'){             $profit = $profit + $transact_money[$i];         }else{             $loss = $loss + $transact_money[$i];         }//end if     }//end for..     $team_profits = $profit - $loss.",";     $final_array .= $team_profits;      echo $final_array; } 

$s = "pnl testing 1,10,pnl testing 2,55"; $res = array(); $result = preg_match_all("{([\w\s\d]+),(\d+)}", $s, $res); $teams  = join(', ', $res[1]); //will "pnl testing 1, pnl testing 2" $amount = join(', ', $res[2]); //will "10, 55" 

Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -