mercredi 1 avril 2015

Extracting a specific part of a string

I have this string:



[25-03-15, 1236], [26-03-15, 3000], [27-03-15, 3054], [30-03-15, 4000]


I want to get two parts from it as below:



['25-03-15','26-03-15','27-03-15','30-03-2015']


and



[1236,3000,3054,4000]


Please guide me how I can perform this task.


PS: I am working of view page of codeigniter.


I'm getting the first thing as:



<?php
$usd=$this->db->query('select transaction_date, SUM(amount) as total
from transactions GROUP BY 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;

?>

Aucun commentaire:

Enregistrer un commentaire