php - Extracting a specific part of a string -
i have string:
[25-03-15, 1236], [26-03-15, 3000], [27-03-15, 3054], [30-03-15, 4000]
i want 2 parts below:
['25-03-15','26-03-15','27-03-15','30-03-2015']
and
[1236,3000,3054,4000]
please guide me how can perform task.
ps: working of view page of codeigniter.
i'm getting first thing as:
<?php $usd=$this->db->query('select transaction_date, sum(amount) total transactions group transaction_date')->result_array(); $str = ''; for($i=0; $i<count($usd); $i++){ if($i!=0){ $str = $str.', ['.date('d-m-y', strtotime($usd[$i]["transaction_date"])).', '.$usd[$i]["total"].']'; }else{ $str = $str.'['.date('d-m-y', strtotime($usd[$i]["transaction_date"])).', '.$usd[$i]["total"].']'; } } echo $str; ?>
try this..
$date = ''; $total = ''; for($i=0; $i<count($usd); $i++){ if($i!=0){ $date .= date('d-m-y', strtotime($usd[$i]["transaction_date"])).', '; $total .= $usd[$i]["total"].', '; }else{ $date .= date('d-m-y', strtotime($usd[$i]["transaction_date"])).', '; $total .= $usd[$i]["total"].', '; } } echo $finaldate='['. $date.']'; echo $finaltotal='['. $total.']';
Comments
Post a Comment