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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:38:36+00:00 2026-06-09T21:38:36+00:00

I am trying to get specific value from an array that is filled with

  • 0

I am trying to get specific value from an array that is filled with news items and its parameters.

My array has 25 items, from 6 different categories, I need to get only category name but not 25 times. If I’m not entirely clear, just say so

This is print_r($this->primary):

Array(
    [0] => stdClass Object
        (
         [title]=> Title 1
         [categoryname]=> Cat1
         [categoryid]=> 2
        )
   [1] => stdClass Object
        (
         [title]=> Title 2
         [categoryname]=> Cat1
         [categoryid]=> 2
        )


   [2] => stdClass Object
        (
         [title]=> Title 3
         [categoryname]=> Cat2
         [categoryid]=> 3
        )
   [3] => stdClass Object
        (
         [title]=> Title 4
         [categoryname]=> Cat2
         [categoryid]=> 3
        )
)

My loop is:

for each ($getids->categories as $key=>$mycategory)
{
    echo ' <h2> CAT NAME SHOULD GO HERE</h2> ';
    for each ($this->primary as $key=>$item){
        if ($mycategory == $item->categoryid){
            echo $item->title;
        }
    }
}

The problem is I need the category name before starting the for each. The stupid thing is that $getids->categories is not giving me anything else but category ID. I can’t fetch it with $this->primary[0] because the items are not grouped per category, but are just rolled in to the array as you can see above ,

any help is appreciated. Thank you!

EDIT: This is print_r($getids->categories):

 Array
 (
     [0] => 11
     [1] => 14
     [2] => 12
     [3] => 13
     [4] => 15
     [5] => 21
     [6] => 20
     [7] => 29
 )
  • 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-09T21:38:37+00:00Added an answer on June 9, 2026 at 9:38 pm

    See if this works for you,

    foreach($this->primary as $key=>$item)
    {
        $headingPrinted = false;
        foreach($getids->categories as $key=>$catID) {
            if($catID == $item->categoryid){
                if (!$headingPrinted) {
                    echo '<h2>'.$item->categoryname.'</h2>';
                    $headingPrinted = true;
                }
                echo $item->title;
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get a specific value from a mysql_fletch_assoc array. I explain. Here
Hello I am trying to print a specific value from an array of objects.
I am trying to get the specific value of file extension in this array.
I am trying to get it so that when a specific <li> is clicked,
I am trying to extract specific index values from an array, and place them
I'm trying to add an entry (that has been read from the keyboard) to
I am trying to get specific version in git and commit it as the
Im trying to get some checkbox with a specific name document.getElementsByName(test); Unfortunatley i cant
I am trying to get a list of shares on a specific machine. So
I'm trying to get a custom handler to work for a specific URL (or

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.