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 8955267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:30:45+00:00 2026-06-15T14:30:45+00:00

Basically I would like to create a function that will in turn create a

  • 0

Basically I would like to create a function that will in turn create a multidimensional array based on another function. Here’s the format of the array I need to create (end result):

'options' => array (
        'one' => array (
            'label' => 'Option One',
            'value' => 'one'
        ),
        'two' => array (
            'label' => 'Option Two',
            'value' => 'two'
        ),
        'three' => array (
            'label' => 'Option Three',
            'value' => 'three'
        )
    )

This will need to be created by a function using another array that was created to store wordpress categories:

$categories = get_categories('hide_empty=0&orderby=name');
$wp_cats = array();
foreach ($categories as $category_list ) {
       $wp_cats[$category_list->cat_ID] = $category_list->cat_name;
}       

And here’s the code I wrote to try accomplish what I’ve described but couldn’t get it to work:

    function wcat2() {
    $i = 0;
    $categories = get_categories();
    foreach( $categories as $category ) {
        $i++;
        array (
        $i => array (
            $category->slug => $category->slug,
            $category->term_id  => $category->term_id
        ),
        );
    }
}

Any ideas of what I’m missing? Help would be much appreciated.

Update: Here’s an illustration of what I need:
descriptin 1

description 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-06-15T14:30:47+00:00Added an answer on June 15, 2026 at 2:30 pm

    Maybe something like:

    function wcat2() {
        $out = array();
        $categories = get_categories();
        foreach( $categories as $category ) {
            $out[$category->term_id] = array(
                'label' => $category->slug,
                'value' => $category->term_id
            );
        }
        return array('options'=>$out);
    }
    print_r(wcat2());
    

    Create a blank variable $out, loop through the categories and on each loop append a new array in the desired format. I’m not sure which is which in regards to the slug/term_id, so you might need to switch those.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So basically I would like to create a function that when alerted, returns the
Having another tough one here guys, basically I would like to check if a
I would like to create a custom data type which basically behaves like an
I would like to basically get all the events that i get invited to
I have a need for a function that will do the following thing: If
Anyone know of a script or already built function that will help me create
I would like to create a simple content slider that would slide content continuously
Basically I would like to store the address of a pointer in a buffer.
Basically I would like to tell MSTest to execute a bit of code before
I would like to set a variable in bash called test_var Basically, I want

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.