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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:17:49+00:00 2026-06-01T17:17:49+00:00

How can I access the property/ value of an array which has been converted

  • 0

How can I access the property/ value of an array which has been converted into an object? For instance, I want to access the value in the index 0,

$obj = (object) array('qualitypoint', 'technologies', 'India');
var_dump($obj->0);

error,

Parse error: syntax error, unexpected T_LNUMBER, expecting T_STRING or
T_VARIABLE or ‘{‘ or ‘$’ in C:…converting_to_object.php on line 11

  • 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-01T17:17:50+00:00Added an answer on June 1, 2026 at 5:17 pm

    The reason you can not access values via $obj->0 its because it against PHP variable naming see http://php.net/manual/en/language.variables.basics.php for more information. even if you use ArrayObject you would still have the same issues

    but there is a patch to this … you can convert all integer keys to string or write your own conversion function

    Example

    $array  = array('qualitypoint', 'technologies', 'India' , array("hello","world"));
    $obj = (object) $array;
    $obj2 = arrayObject($array);
    function arrayObject($array)
    {
        $object = new stdClass();
        foreach($array as $key => $value)
        {
            $key = (string) $key ;
            $object->$key = is_array($value) ? arrayObject($value) : $value ;
        }
        return $object ;
    }
    var_dump($obj2->{0}); // Sample Output
    var_dump($obj,$obj2); // Full Output to see the difference 
    
    
    $sumObject = $obj2->{3} ; /// Get Sub Object
    var_dump($sumObject->{1});  // Output world
    

    Output

       string 'qualitypoint' (length=12)
    

    Full output

    object(stdClass)[1]
      string 'qualitypoint' (length=12)
      string 'technologies' (length=12)
      string 'India' (length=5)
    
        array
          0 => string 'hello' (length=5)
          1 => string 'world' (length=5)
    
    object(stdClass)[2]
      public '0' => string 'qualitypoint' (length=12)
      public '1' => string 'technologies' (length=12)
      public '2' => string 'India' (length=5)
      public '3' => 
        object(stdClass)[3]
          public '0' => string 'hello' (length=5)
          public '1' => string 'world' (length=5)
    

    Multi Array Outpur

    Thanks

    🙂

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

Sidebar

Related Questions

I can't figure out how can I access a value which has been updated
Why I can access Session object in Page_Load method in instance of System.Web.UI.Page, but
I can put value into array and here is my code and prob. Search.h
I access property value from a class object at run-time using reflection in C#.
I have a ViewController class that has a property that is the model which
I can define a class with a property to access my ivars from outside
Accessing an array element with the following line works great; if (dataset[i].properties.property == value)
In the following setter, I can access the property backing field directly or through
I want it so I can click a button and it changes the value
I would like to bring access to an internal array with a Property, but

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.