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

  • SEARCH
  • Home
  • 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 7087225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:38:52+00:00 2026-05-28T07:38:52+00:00

This is what I’m trying to arrive at: array ( ‘category_0’ => array (

  • 0

This is what I’m trying to arrive at:

array (
  'category_0' => 
  array (
    'count' => 12,
    'avg' => 11,
  ),
  'category_1' => 
  array (
    'count' => 14,
    'avg' => 13,
  ),
  'category_2' => 
  array (
    'count' => 16,
    'avg' => 15,
  ),
  'category_3' => 
  array (
    'count' => 18,
    'avg' => 17,
  ),
)

From the following:

$category = 
array (
  0 => '9',
  1 => '10',
  2 => '11',
  3 => '12',
)

and:

$count =
array (
  0 => '12',
  1 => '14',
  2 => '16',
  3 => '18',
)

and:

$avg = 
array (
  0 => '11',
  1 => '13',
  2 => '15',
  3 => '17',
)

I’ve arrived at the $count and $avg variables by performing some other methods using a foreach on the $category and the array_map function. Now I need to rejoin everything per the intial example. I’ve tried array_merge() but am unable to get it to work correctly. The key name of ‘category_x’ is unimportant. I’m not even sure if it’s possible to get the final result in the order I need it. Any help would be appreciated.

  • 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-28T07:38:53+00:00Added an answer on May 28, 2026 at 7:38 am

    Using a combination of array_keys and a foreach loop, you can easily accomplish this.

    Example:

    <?php
    
    $category = array (
        0 => '9',
        1 => '10',
        2 => '11',
        3 => '12'
    );
    $count = array (
        0 => '12',
        1 => '14',
        2 => '16',
        3 => '18'
    );
    $avg = array (
        0 => '11',
        1 => '13',
        2 => '15',
        3 => '17'
    );
    
    $out = array();
    $key = array_keys($category);
    foreach ($key as $key) {
        $out["category_{$key}"] = array(
            'count' => isset($count[$key]) ? $count[$key] : 0,
            'avg' => isset($avg[$key]) ? $avg[$key] : 0
        );
    }
    print_r($out);
    

    Output:

    Array
    (
        [category_0] => Array
            (
                [count] => 12
                [avg] => 11
            )
    
        [category_1] => Array
            (
                [count] => 14
                [avg] => 13
            )
    
        [category_2] => Array
            (
                [count] => 16
                [avg] => 15
            )
    
        [category_3] => Array
            (
                [count] => 18
                [avg] => 17
            )
    
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my first post here and I wanted to get some input from
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
This is as close as I've gotten to successfully populating an expandable listview from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This is my first time using Magento. I upgraded this site from 1.4.1.1 to
Does anyone know how can I replace this 2 symbol below from the string
this is my code to turn a byte[] array into an image unsafe {
This problem has been bugging me since forever. I have an array and in
This is a bit of a long shot, but if anyone can figure it

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.