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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:19:26+00:00 2026-05-18T20:19:26+00:00

I have this PHP one dimensional array: Array ( [Female–N] => 11 [Male–N] =>

  • 0

I have this PHP one dimensional array:

  Array
    (
        [Female--N] => 11
        [Male--N] => 11
        [Humans--N] => 11
        [Adult--N] => 8
        [Adolescent--N] => 8
        [Reaction Time-physiology--N] => 6
        [Acoustic Stimulation-methods--N] => 6
        [Schizophrenia-genetics--Y] => 5
        [Motion Perception--N] => 3
    )

And i want a new array from this that looks like (i think this tow-dimensional..?):

Array
        (
            [Female][N] => 11
            [Male][N] => 11
            [Humans][N] => 11
            [Adult][N] => 8
            [Adolescent][N] => 8
            [Reaction Time-physiology][N] => 6
            [Acoustic Stimulation-methods][N] => 6
            [Schizophrenia-genetics][Y] => 5
            [Motion Perception][N] => 3
        )

Can i use split method on key elements?

Little bit harder… i also need to split on the single ‘_’ underscore, i did this to prevent the columns getting mixed up… But the example below doesn’t do the job right…

$new_array = array();
foreach($MeshtagsArray as $key => $value) {
    $parts = explode('__', $key, 2);
    $parts2 = explode('_', $key, 2);
    $new_array[] = array(
        'discriptor' => $parts[0],
    'qualifier' => $parts2[1],
        'major' => $parts[1],
        '#occurence' => $value
    );

So the output should be something like:

[0] => Array
        (
            [discriptor] => Female
            [qualifier] => 
            [major] => N
            [#occurence] => 11
........
[5] => Array
        (
            [discriptor] => Reaction Time
            [qualifier] => physiology
            [major] => N
            [#occurence] => 6

Best regards,
Thijs

  • 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-18T20:19:26+00:00Added an answer on May 18, 2026 at 8:19 pm

    UPDATED

    $new_array = array();
    foreach($old_array as $key => $value) {
        $parts1 = explode('--', $key, 2);
        $parts2 = explode('-', $parts1[0], 2);
        $new_array[] = array(
            'descriptor' => $parts2[0],
            'qualifier' => count($parts2) > 1 ? $parts2[1] : '',
            'major' => $parts1[1],
            '#occurence' => $value
        );
    }
    

    $new_array will now be a numerically indexed, multidimensional array. Each top level key will contain an associative array of the elements you require.

    In the future, feel free to explain the entire problem from the beginning, that way we can all better help you!

    Explanation

    According to php.net:

    array explode ( string $delimiter , string $string [, int $limit ] )

    Returns an array of strings, each of which is a substring of string formed by splitting it on boundaries formed by the string delimiter.

    The array in your problem is associative; it’s keys are strings. This makes it is a simple matter to iterate over the array with foreach and explode the keys into parts. I use a limit parameter to ensure that there will be no more than two parts.

    Also, since one delimiter is a doubled version of the other, we have to first explode on the double -- delimiter, and then explode on the single - delimiter.

    Technically, we could have used a single explode—with no limit parameter—and the single - delimiter. Then we could have inferred which element part belonged where. However, sometimes there is no qualifier. To get around this problem, I’ve used two explodes, and a ternary operator that counts the returned number of elements from the second explode.

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

Sidebar

Related Questions

I have a multi dimensional array in PHP. $f = array('one' => array(*doesntmatter*), two
I have an single-dimensional array of PHP objects. Each object has two attributes, one
This is driving me crazy. I have this one php file on a test
If I have a button like the one in this image : http://www.freeimagehosting.net/image.php?4cd775814c.png how
I have a multi-dimensional array, which basically consists of one sub-array for each year.
I have a form like this: one.php <form id='myFormId' name='myFormName'> <input type='text' name='myTextField'> <a
I have this php code, with which I am trying to generate a popup
I have this PHP code echo '<a href=# onclick=updateByQuery(\'Layer3\', ' . json_encode($query) . ');>Link
Say i have this PHP code: $FooBar = a string; i then need a
I have this simple php script <?php echo '<pre>'; // Outputs all the result

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.