how to convert data type from result_object codeigniter

124 Views Asked by At

I have an array of objects from the query as follows :

Array
(
    [0] => stdClass Object
        (
            [row_number] => 1
            [cash_id] => 30938
            [closing_id] => 
            [is_closed] => 0
            [cash_date] => 2018-04-03
            [store_id] => 13
            [store_code] => 504
            [store_account] => ST0013
            [store_vendor] => ES0013
            [store_dwds] => 01R-0101A006S0013
            [store_name] => KARTIKA  CHANDRA
            [area_id] => 11
            [area_code] => A11
            [area_name] => Area 11
            [region_id] => 1
            [region_code] => R01
            [region_name] => Region 1
            [closing_date] => 
            [closing_type] => 
            [closing_type_desc] => 
            [cash_amount] => 6000000.0000
            [closing_amount] => 
            [update_time] => 
            [update_by_username] => 
            [update_by_first_name] => 
            [update_by_last_name] => 
            [update_by_email] => 
        )
   [1] => stdClass Object
        (
            [row_number] => 1
            [cash_id] => 30938
            [closing_id] => 
            [is_closed] => 0
            [cash_date] => 2018-04-03
            [store_id] => 13
            [store_code] => 504
            [store_account] => ST0013
            [store_vendor] => ES0013
            [store_dwds] => 01R-0101A006S0013
            [store_name] => KARTIKA  CHANDRA
            [area_id] => 11
            [area_code] => A11
            [area_name] => Area 11
            [region_id] => 1
            [region_code] => R01
            [region_name] => Region 1
            [closing_date] => 
            [closing_type] => 
            [closing_type_desc] => 
            [cash_amount] => 6000000.0000
            [closing_amount] => 
            [update_time] => 
            [update_by_username] => 
            [update_by_first_name] => 
            [update_by_last_name] => 
            [update_by_email] => 
        )
)


how do i change the is_closed object into a boolean data type ?

thanks,

1

There are 1 best solutions below

0
ahmad On

You'll have to cast it to a boolean in your loop when you use it.

array_walk($Result, function ($item) {
    $item->is_closed = (bool) $item->is_closed;    
});