lundi 27 juin 2016

How can make custom array in php?

When I run typical query then found an array:

[0] => stdClass Object
    (
        [id] => 5132
        [service_year] => 2016
        [service_month] => April
        [country_id] => 116
        [country] => Kenya
        [mobile_operator_id] => 3
        [mobile_operator] => Airtel
        [service_id] => 16
        [gross_revenue_actual] => 11500.000000
        [content_partner_share] => 1000.000000
        [service] => Christianity Portal
        [collected_at] => 2016-06-24 09:59:19
        [invoice_id] => 105
    )

[1] => stdClass Object
    (
        [id] => 4982
        [service_year] => 2016
        [service_month] => May
        [country_id] => 116
        [country] => Kenya
        [mobile_operator_id] => 3
        [mobile_operator] => Airtel
        [service_id] => 16
        [gross_revenue_actual] => 11500.000000
        [content_partner_share] => 1000.000000
        [service] => Christianity Portal
        [collected_at] => 2016-06-24 10:02:21
        [invoice_id] => 106
    )

[2] => stdClass Object
    (
        [id] => 4732
        [service_year] => 2016
        [service_month] => June
        [country_id] => 116
        [country] => Kenya
        [mobile_operator_id] => 3
        [mobile_operator] => Airtel
        [service_id] => 16
        [gross_revenue_actual] => 11000.000000
        [content_partner_share] => 1000.000000
        [service] => Christianity Portal
        [collected_at] => 2016-06-24 13:13:42
        [invoice_id] => 114
    )

[3] => stdClass Object
    (
        [id] => 5522
        [service_year] => 2015
        [service_month] => December
        [country_id] => 51
        [country] => Congo(Republic of)
        [mobile_operator_id] => 31
        [mobile_operator] => MTN
        [service_id] => 56
        [gross_revenue_actual] => 11500.000000
        [content_partner_share] => 1000.000000
        [service] => Music On Demand
        [collected_at] => 2016-06-24 11:26:09
        [invoice_id] => 101
    )

By using above array, If service_year, country, mobile_operator, service are same but month are different then I want to create new array like below

$finalarray = {
0 = {
[id] => 4732,
[service_year] => 2016,
[service] => Christianity Portal,
[country] => Kenya,
[mobile_operator] => Airtel,
array{
array[April] {
[gross_revenue_actual] => 11500.000000
[content_partner_share] => 1000.000000
[collected_at] => 2016-06-24 10:02:21
},
array[May] {
    [gross_revenue_actual] => 11000.000000
    [content_partner_share] => 1000.000000
    [collected_at] => 2016-06-24 13:13:42
    },
    array[June] {
        [gross_revenue_actual] => 11000.000000
        [content_partner_share] => 1000.000000
        [collected_at] => 2016-06-24 13:13:42
        },
    }
}
1 = {
    [id] => 5522
    [service_year] => 2015
    [service_month] => December
    [country_id] => 51
    [country] => Congo(Republic of)
    [mobile_operator_id] => 31
    [mobile_operator] => MTN
    [service_id] => 56
    [gross_revenue_actual] => 11500.000000
    [content_partner_share] => 1000.000000
    [service] => Music On Demand
    [collected_at] => 2016-06-24 11:26:09
    [invoice_id] => 101
}

}

How can I do this when I have used Laravel 5 framework? Is it possible to modify my query to get such type of array?

I appreciate all hints and responses. Thanks ahead.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/290rjqN
via IFTTT

Aucun commentaire:

Enregistrer un commentaire