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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:20:20+00:00 2026-05-23T12:20:20+00:00

I have an array which is generated from an XML file and it shows

  • 0

I have an array which is generated from an XML file and it shows me like below when printed with print_r

Array
(
    [cxname] => Global CX 87 123
    [ipaddress] =>  66.240.55.87
    [slots] => Array
        (
            [slot] => Array
                (
                    [0] => Array
                        (
                            [slotno] =>  1
                            [cardtype] => 0x24 
                            [modelno] =>  OP3524J
                            [label1] => OP 
                            [label2] =>  Module
                            [severity] => Minor
                        )

                    [1] => Array
                        (
                            [slotno] =>  2
                            [cardtype] => 0x25 
                            [modelno] =>  OP3524K
                            [label1] => OP 
                            [label2] =>  Module
                            [severity] => Major
                        )

                )

        )

)

When I print like this, it shows nothing

 echo $dataArray->cxname;

But following code works and prints “Global CX 87 123 “

 echo $dataArray["cxname"];

How can I make it work as above example.

  • 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-23T12:20:20+00:00Added an answer on May 23, 2026 at 12:20 pm

    Just do this:

    $dataArray = (object)$dataArray;
    

    It’ll convert the array in an stdClass object and allow you to use it that way. Please note that this will only convert the first level for the array. You’ll have to create a function to recurse through the array if you want to access all levels that way. For example:

    <?php
    function arrayToObject($array) {
        if(!is_array($array)) {
            return $array;
        }
    
        $object = new stdClass();
        if (is_array($array) && count($array) > 0) {
          foreach ($array as $name=>$value) {
             $name = strtolower(trim($name));
             if (!empty($name)) {
                $object->$name = arrayToObject($value);
             }
          }
          return $object; 
        }
        else {
          return FALSE;
        }
    }
    

    For more information, have a look at http://www.richardcastera.com/blog/php-convert-array-to-object-with-stdclass. To find out about typecasting, you can also read http://www.php.net/manual/en/language.types.object.php#language.types.object.casting.

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

Sidebar

Related Questions

I have an indexed array which I've generated from an associative array with this
I have a multi-dimensional array of databases, which was generated from my server: //
I have a generated nested Array which I store some data. How can i
i have an array which could look like this: $config[$name][$array]['key'] = 'value'; // here
I have one spinner in which few values are there from strings.xml and I
I have this array which gets the last table from a database. However the
i have a table array dynamically generated from a data query and stored in
I have a dynamically generated array from a database. Basically it's an array of
I've got a Javascript file which is automatically generated from a legacy app which
Example: I have a list of friends which I retrieve as XML from a

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.