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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:51:48+00:00 2026-05-27T23:51:48+00:00

How do I check that an array key equals a value with an array

  • 0

How do I check that an array key equals a value with an array like this:

Array ( [0] => stdClass Object ( [subCategory] => All Headphones [description] => [image] => ) [1] => stdClass Object ( [subCategory] => Behind-the-Neck Headphones [description] => [image] => ) [2] => stdClass Object ( [subCategory] => Clip-On Headphones [description] => [image] => ) [3] => stdClass Object ( [subCategory] => Earbud Headphones [description] => [image] => ) [4] => stdClass Object ( [subCategory] => Kids' Headphones [description] => [image] => ) )

I’ve tried using this code:

if(array_key_exists('subCategory',$array) {
          echo "Exists";
}
  • 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-27T23:51:49+00:00Added an answer on May 27, 2026 at 11:51 pm

    That wont work because you have an array of standard objects… the only array keys even present are integers. So the question is what are you trying to detect? If you want to check the if an object has the subCategory property you can do isset($obj->subCategory). If you want to ensure that each object in your array has that property then you need to loop:

    function hasSubCategory($array){
      foreach($array as $element) {
        if(!isset($element->subCategory)){
          return false; // if any object doesnt have the property
        }
      }
    
      return true; // if all objects have the property
    }
    

    I dont think thats what you really want to do though, some more info would be helpful.

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

Sidebar

Related Questions

I am using this code to check that array is present in the HashMap
i have this code that will check the array contains the specific string and
I'd like to know how to check an array that got several variables in
Givven an object with Key as an Array (of position) and Value as an
I have a simple recursive array function that looks like this: function recursive_array($results) {
I have an array that goes like this $array = array('key1' => $_GET['value1'], 'key2'
I am trying this code to check if a value exists in an array.
I have one array that contains some settings that looks like basically like this:
I would like to check that I have workingDir = C:\Users\~\Temp\workspace_folder; for i=1:2 %
How do i check if a specific array key exist and how to compare

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.