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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:28:05+00:00 2026-05-26T02:28:05+00:00

I have a 3D array. I need to extract the following: the number of

  • 0

I have a 3D array. I need to extract the following:

  1. the number of occurrences of unique items in deepest level array
  2. the number of co-occurrences of certain items in deepest level array

Array looks like this:

$arr = (
       [0] => array([0] => array([flag][token][value])
                    [1] => array([flag][token][value])
                    )
       )

I tried looping through the array using a for loop and an if statement, like this:

$new_arr1 = ""; // $new_arr1 = array(); //same thing, the later code doesn't work

for ($i=0; $i<count($arr);$i++)
{
    for ($j=0; $j<count($arr[$i]); $j++)
        {

          $value= $arr[$i][$j][value];

          if ($arr[$i][$j][flag] == "noun")
             array_push($new_arr1, $value)

          elseif ($arr[$i][$j][flag] == "verb")
             array_push($new_arr2, $value)
        }
}

did the same thing with switch statement, couldn’t get it to work. By doing this kind of conditioning I was hoping to get all of the values from the deepest level array that meet the certain criteria into one array, and then perform *array_count_values* on them. That would give me the following:

for flag == “noun”, value of value element stored in $new_arr1, and for flag == “verb”, value of value element stored in $new_arr2:

$new_arr1 = (
           [dog] => 7
           [cat] => 2
           [horse] => 4
          );

$new_arr2 = (
           [chase] => 2
           [eat] => 5
           [pwn] => 3
          );

this would give me a count of unique values of the deepes level array that I can’t access using *array_uniqe* function.

Besides that, I need to perform a count of co-occurrences of these values, something like this:

count the number of times that some token with certain flag comes before or after another token with a certain flag:

pseudocode:

$count=0;
if ( (($arr[$i][$j][flag] == "noun") && ($arr[$i][$j][value] == "dog")) &&
     (($arr[$i][$j+/-1][flag] == "verb") && ($arr[$i][$j+/-1][value] == "chase"))
   )
$count++;

$counter = array($count = array($arr[$i][$j][value]), $arr[$i][$j+/-1][value])

that would basically give the following:

counter:
array(
      "7" => ([0] => "dog", [1] => "chase")
      "4" => ([0] => "cat", [1] => "eat")
     )

where the “7” and “4” are the names of the associative array, while “dog” and “chase” are the values stored in another array.

     )
  • 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-26T02:28:06+00:00Added an answer on May 26, 2026 at 2:28 am

    I’m not sure if I follow your question 100%, but something like this might work:

    $verb_array = array();
    $noun_array = array();
    foreach($arr as $index => $data){
        if($data['flag'] == 'noun'){
            if(isset($noun_array[$data['value']])){
                $noun_array[$data['value']]++;
            }
            else{
                $noun_array[$data['value']] = 0;
            }
        }
        else if($data['flag'] == 'verb'){
            if(isset($noun_array[$data['value']])){
                $verb_array[$data['value']]++;
            }
            else{
                $verb_array[$data['value']] = 0;
            }            
        }
    }
    

    Then to get the count of occurrences:

    $noun_count = count($noun_array);
    $verb_count = count($verb_array);
    

    And if you need the count of a particular item, it will exist inside of the array.

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

Sidebar

Related Questions

I have an array like this: object[] args and need to insert those args
I have an array that looks like this Array ( [1] => Array (
I have an array of 30 values and I need to extract from this
I have several array to deal with. I need to extract the most duplicate
I have following array, that I need to operate by hand on bitmaps. const
I have an array Items which has 10 elements. I need to remove the
I have the following string and need to extract the text inside the div's
I have a backbone collection Platforms . The structure of Platforms looks like this:
I have a string like this that I need to parse into a 2D
I have an array of char s and I need to extract subsets of

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.