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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T20:11:10+00:00 2026-05-21T20:11:10+00:00

Here is what my object looks like with print_r (this is an object returned

  • 0

Here is what my object looks like with print_r (this is an object returned by the PHP SDK for the Amazon Web Services Simple DB.

[GetAttributesResult] => CFSimpleXML Object
            (
                [Attribute] => Array
                    (
                        [0] => CFSimpleXML Object
                            (
                                [Name] => data_datein
                                [Value] => 2011-04-23
                            )

                        [1] => CFSimpleXML Object
                            (
                                [Name] => data_estatus
                                [Value] => 0
                            )

                        [2] => CFSimpleXML Object
                            (
                                [Name] => data_status
                                [Value] => 1
                            )

                        [3] => CFSimpleXML Object
                            (
                                [Name] => data_title
                                [Value] => Company Info
                            )

                        [4] => CFSimpleXML Object
                            (
                                [Name] => data_tags
                                [Value] => firsttag
                            )

                        [5] => CFSimpleXML Object
                            (
                                [Name] => data_tags
                                [Value] => secondtag
                            )

                        [6] => CFSimpleXML Object
                            (
                                [Name] => data_tags
                                [Value] => thirdtag
                            )

                        [7] => CFSimpleXML Object
                            (
                                [Name] => data_files
                                [Value] => company_info.flv
                            )

                        [8] => CFSimpleXML Object
                            (
                                [Name] => data_id
                                [Value] => 8993
                            )

                    )

            )

I have a function that iterates over the GetAttributesResult Object and creates an associative array that makes it easy to reference my fields by their names. One of my Names is data_tags, which is repeated an unknown number of times. I would like to return data_tags as a simple indexed array of those values. Here’s my function, which doesn’t work.

function attrToArray($select) { 
$results = array(); 
$x = 0; 
foreach($select->body->GetAttributesResult as $result) { 
    foreach ($result as $field) { 
        if (array_key_exists($field,$results[$x])) {
            $results[$x][ (string) $field->Name ][] = (string) $field->Value;
        } else {
            $results[$x][ (string) $field->Name ] = (string) $field->Value; 
        }
    } 
    $x++; 
} 
return $results; 
}

I don’t know if this is the most elegant solution, but I don’t see why it wouldn’t work. array_key_exists doesn’t return true. By mistake I was able to test as in_array($field-Name,$results[$x]) and that built the array of my repeated $field->Name values… but it also converted all of the other values into single item nested array… so it would seem that it returned true more than I thought it would have. Although the hyphen in there was by mistake I meant to use -> which doesn’t return true… so I’m very confused by what is going on there. Here’s the print_r to show what came back.

Array ( [0] => Array ( 
[data_datein] => 2011-04-23 
[data_estatus] => 0 
[data_status] => Array ( [0] => 1 ) 
[data_title] => Array ( [0] => Company Info ) 
[data_tags] => Array ( 
    [0] => firsttag
    [1] => secondtag 
    [2] => thirdtag ) 
[data_files] => Array ( [0] => company_info.flv ) 
[data_id] => Array ( [0] => 8993 ) ) ) 

Any pointers, suggestions or instruction on how I might handle this better… and at very least if someone can figure out how I can get to the above array without the nested arrays on the other non-redundant fields. Very much appreciated!

Here is the print_r() of $result
CFSimpleXML Object
(
[Attribute] => Array
(
[0] => CFSimpleXML Object
(
[Name] => data_datein
[Value] => 2011-04-23
)

        [1] => CFSimpleXML Object
            (
                [Name] => data_estatus
                [Value] => 0
            )

        [2] => CFSimpleXML Object
            (
                [Name] => data_title
                [Value] => 0001 01 Company Name
            )

        [3] => CFSimpleXML Object
            (
                [Name] => data_status
                [Value] => 1
            )

        [4] => CFSimpleXML Object
            (
                [Name] => data_tags
                [Value] => good stuff
            )

        [5] => CFSimpleXML Object
            (
                [Name] => data_tags
                [Value] => save tags
            )

        [6] => CFSimpleXML Object
            (
                [Name] => data_tags
                [Value] => tagger works
            )

        [7] => CFSimpleXML Object
            (
                [Name] => data_files
                [Value] => 0001_01_company_name.flv
            )

        [8] => CFSimpleXML Object
            (
                [Name] => data_id
                [Value] => yFKwIxjIhH
            )

    )

)

and here is a print_r() of $field (iterated and separated by <hr> tags.)

  CFSimpleXML Object
  (
      [Name] => data_datein
      [Value] => 2011-04-23
  )
  <hr>CFSimpleXML Object
  (
      [Name] => data_estatus
      [Value] => 0
  )
  <hr>CFSimpleXML Object
  (
      [Name] => data_title
      [Value] => 0001 01 Company Name
  )
  <hr>CFSimpleXML Object
  (
      [Name] => data_status
      [Value] => 1
  )
  <hr>CFSimpleXML Object
  (
      [Name] => data_tags
      [Value] => good stuff
  )
  <hr>CFSimpleXML Object
  (
      [Name] => data_tags
      [Value] => save tags
  )
  <hr>CFSimpleXML Object
  (
      [Name] => data_tags
      [Value] => tagger works
  )
  <hr>CFSimpleXML Object
  (
      [Name] => data_files
      [Value] => 0001_01_company_name.flv
  )
  <hr>CFSimpleXML Object
  (
      [Name] => data_id
      [Value] => yFKwIxjIhH
  )
  • 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-21T20:11:11+00:00Added an answer on May 21, 2026 at 8:11 pm
    function attrToArray($select) { 
    $results = array(); 
    $x = 0;
    foreach ( $select->body->GetAttributesResult as $result ) {
        foreach ( $result as $field ) {
            $check = (string) $field->Name;
            if (isset($field) && array_key_exists($check, $results[$x] ) ) {
                if ( ! is_array( $results[ $x ][$check] ) ) {
                    $val = (string) $results[ $x ][$check];
                    $results[ $x ][ $check ] = array();
                    $results[ $x ][ $check ][] = $val;
                }
            $results[ $x ][ $check ][] = (string) $field->Value;
            } else {
                $results[ $x ][ $check ] = (string) $field->Value;
            }
        }
        $x++; 
    }
    return $results; 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Python 2.x module.py file that looks like this: class A(object): KEYWORD
I have a simple Session_Start code that looks like this: Sub Session_Start(ByVal sender As
Here's a simple method with a foreach loop: IEnumerable<XElement> FieldsToXElements(object instance) { var fieldElements
I am a little confused here. I would like to do something like this:
I have some xml that looks like this: <?xml version=1.0?> <data> <items> <item><timestamp>2011-07-11T09:01:42Z</timestamp><title><![CDATA[ some
I have an xml file that looks like this: <!DOCTYPE ROOT SYSTEM zombie.dtd> <ROOT>
Here's my binding source object: Public Class MyListObject Private _mylist As New ObservableCollection(Of String)
Here is my SQLCommand object: oCommand.CommandText = INSERT INTO hits (id,client_id,client_ip,page,vars) VALUES _ (@@IDENTITY,@client_id,@ip,@page,@vars)
here is what a I'm doing: object ReturnMatch(System.Type type) { foreach(object obj in myObjects)
Here's the scenario-- you've got a JSON object on the browser, and let's say

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.