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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:47:36+00:00 2026-05-14T06:47:36+00:00

$jj_post is the array output debug via print_r() . This variable is an array

  • 0

$jj_post is the array output debug via print_r(). This variable is an array of objects:

Array
(
    [0] => stdClass Object
        (
            [ID] => 2571
        )

)

I access the object property, ID, via code like this:

$jj_post_id = $jj_post[0]; 
$jj_ID = $jj_post_id->ID;

So, is there a shorter way, cause this is the only thing I know and I feel the code little bit too long?

  • 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-14T06:47:36+00:00Added an answer on May 14, 2026 at 6:47 am

    Well if you are sure $jj_post is always going to be an array, and that it will always contain an stdClass object, then you should access like so:

    $jj_ID = $jj_post[0]->ID;
    

    But it is not always so sometimes. You may not always know the contents of a variable so you need to do some checking to verify that you access areas that are safe and available.

    How long the code is shouldn’t be an issue if it performs the job well.

    In my opinion, you have two alternatives:

     $jj_ID = @$jj_post[0]->ID;
    

    This ensures that the runtime errors are silently handled, and not thrown to the standard output.

    Another way would be to check absolutely for presence of each type:

    $jj_ID = "";
    if(is_array($jj_post))
    {
      $jj_post_id = $jj_post[0]; 
      if(!empty($jj_post_id))
      {
        $jj_ID = $jj_post_id->ID;
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 533k
  • Answers 533k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer What do you mean by "connect it with wordpress using… May 17, 2026 at 12:26 am
  • Editorial Team
    Editorial Team added an answer Most modern std::string implementations1 save very small strings directly on… May 17, 2026 at 12:26 am
  • Editorial Team
    Editorial Team added an answer The most widely used documentation standard in the PHP world… May 17, 2026 at 12:26 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

We have a loop in our PHP code which inserts rows into a table.
I have been refactoring throwaway code which I wrote some years ago in a
I have an application which consumes a WCF Service. I have no access to
I'd like to select the image source url from html code using javascript regexp.
I had the following code in a test.I am confused about what (i,j) evaluates,while
I am puzzled by why the output is not what I expect it to
Basically, I have a matrix class like this (with a lot of operator overloads
I am trying to change/replaced the action attribute in a form but am having
Suppose I have such chunk of a sentence: (NP (NP (DT A) (JJ single)
I have a little problem. Class ll: interface jj{ public class ll implements gg{

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.