Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4608582
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:51:56+00:00 2026-05-22T00:51:56+00:00

I have a multidimensional array which is created by a MySQL query which collects

  • 0

I have a multidimensional array which is created by a MySQL query which collects results based on a number of groups and sums. The array is below.

I’m interested in the costtotal and hitcount for each type of ‘ad_type’, ‘click_status’ and ‘link_status’ variation.

The possible values of the 3 types of variable are known:
i.e.

  • ad_type 0 / 1
  • click_status 2 / 3
  • link_status 1 / 2

I would like to create a new array based on the results of each combination.

I’m guessing a search or split would do it but I’m not having much luck.

How would I go about doing this?

Array
(
    [0.261346210037681] => Array
        (
            [costtotal] => 0.0015
            [hitcount] => 1
            [ad_type] => 0
            [click_status] => 2
            [link_status] => 1
        )

    [0.190427019438173] => Array
        (
            [costtotal] => 0.001
            [hitcount] => 1
            [ad_type] => 0
            [click_status] => 3
            [link_status] => 1
        )

    [0.563596305962276] => Array
        (
            [costtotal] => 0.007
            [hitcount] => 5
            [ad_type] => 1
            [click_status] => 2
            [link_status] => 1
        )

    [0.893211513658251] => Array
        (
            [costtotal] => 0
            [hitcount] => 3
            [ad_type] => 1
            [click_status] => 2
            [link_status] => 2
        )

    [0.209184847035617] => Array
        (
            [costtotal] => 0.004
            [hitcount] => 2
            [ad_type] => 1
            [click_status] => 3
            [link_status] => 1
        )

    [0.73545002260753] => Array
        (
            [costtotal] => 0
            [hitcount] => 1
            [ad_type] => 1
            [click_status] => 3
            [link_status] => 2
        )

)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T00:51:57+00:00Added an answer on May 22, 2026 at 12:51 am

    If I fully understand what you want, then this code should satisfy you:

    function generateClickCounterInfo() {
        return array(
            'costTotal' => 0.0,
            'hitCount' => 0
        );
    }
    
    function generateLinkStatusStructure() {
        return array(
            1 => generateClickCounterInfo(),
            2 => generateClickCounterInfo()
        );
    }
    
    function generateClickStatusStructure() {
        return array(
            2 => generateLinkStatusStructure(),
            3 => generateLinkStatusStructure()
        );
    }
    
    function generateAdTypeArrayStructure() {
        return array(
            0 => generateClickStatusStructure(),
            1 => generateClickStatusStructure()
        );
    }
    
    function getClickCounterReport(array $data) {
        $result = generateAdTypeArrayStructure();
    
        foreach ($data as $key => $value) {
            $adType      = $value['ad_type'];
            $clickStatus = $value['click_status'];
            $linkStatus  = $value['link_status'];
    
    
            if (!isset($result[$adType])
                || !isset($result[$adType][$clickStatus])
                || !isset($result[$adType][$clickStatus][$linkStatus])) {
                throw new Exception(
                    "Input data does not conform to expected format. " .
                    "ad_type = {$adType}, click_status = {$clickStatus}, link_status = ${linkStatus}"
                );
            }
    
            $costTotal = $value['costtotal'];
            $hitCount  = $value['hitcount'];
    
            $result[$adType][$clickStatus][$linkStatus]['costTotal'] += $costTotal;
            $result[$adType][$clickStatus][$linkStatus]['hitCount']  += $hitCount;
        }
    
        return $result;
    }
    

    And than getClickCounterReport($data) (where $data is data provided by you) will produce following array: http://pastebin.ubuntu.com/607464/

    P.S. Knowing disadvantages:

    • No OOP (but these functions will be easy to transform to methods)
    • Magick numbers (0, 1, 2, 3 etc)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

how do I make a pointer to a multidimensional array, which have a unknown
I have a multidimensional array which I would like to sort by two factors:
I have a multidimensional array which is the result of a JOIN statement. And
I have a multidimensional array $BlockData[] which has 13 dimensions in it and 'n'
I have a multidimensional array. I need to search it for a specific range
I have CSV data loaded into a multidimensional array. In this way each row
I have just noticed that a multidimensional array in C# does not implement IEnumerable<T>
Okay, I have a multi-dimensional array which is statically-allocated. I'd very much like to
I have a multidimensional numpy array, and I need to iterate across a given
i have this multidimensional array in php and I need be able to access

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.