I am using laravel 5. I queried the list of dates from this sql statement:
//query tarikh tamat kursus
$datatarikhTamat = DB::table('itemregistrationdetail')
->select('itemregistrationdetail.daytamat_kursus', 'itemregistrationdetail.monthtamat_kursus', 'itemregistrationdetail.yeartamat_kursus')
->where('itemregistrationdetail.itemregistrationid', $id)
->get();
$data = json_decode($datatarikhTamat, true);
The decoded query will show this output:
array:4 [▼
0 => array:3 [▼
"daytamat_kursus" => 28
"monthtamat_kursus" => "July"
"yeartamat_kursus" => 2011
]
1 => array:3 [▼
"daytamat_kursus" => 27
"monthtamat_kursus" => "0"
"yeartamat_kursus" => 2013
]
2 => array:3 [▼
"daytamat_kursus" => 14
"monthtamat_kursus" => "0"
"yeartamat_kursus" => 2013
]
3 => array:3 [▼
"daytamat_kursus" => 11
"monthtamat_kursus" => "April"
"yeartamat_kursus" => 2014
]
]
day, month and year of each date are from different columns of the table. I want to have those date to grouped together and displayed in a table. For example: The muldtidimensiarray of :
array:12 [▼
0 => "28 July 1022"
1 => "27 0 2013"
2 => "14 0 2013"
3 => "11 April 2014"
]
can be grouped using implode to turn into a string "11 April 2014".
I had using this code to implode the array but it results differently.
//tarikh tamat kursus
//**************** format the value of the date************************
$data = json_decode($datatarikhTamat, true);
$val_arr = array();
foreach($data as $val)
{
foreach($val as $key => $value)
{
$val_arr[] = $value;
}
}
$dataTarikhTamat = implode("-", $val_arr);
dd($val_arr);
This will produce this output:
array:12 [▼
0 => 28
1 => "July"
2 => 2011
3 => 27
4 => "0"
5 => 2013
6 => 14
7 => "0"
8 => 2013
9 => 11
10 => "April"
11 => 2014
]
How can I modify the codes to get an indexed array of the dates?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire