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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:29:27+00:00 2026-05-23T14:29:27+00:00

I am trying to build an array and I am looping through the values

  • 0

I am trying to build an array and I am looping through the values of an XML document, I have everything pulling out great using xpath, here’s my code:

    function parseAccountIds($xml) {

    $arr = array();

    foreach($xml->entry as $k => $v) {

        $acctName = $v->title;

        $prop = $v->xpath('dxp:property');
        foreach($prop as $k1 => $v1) {
            if($v1->attributes()->name == "ga:accountId")
                $acctId = (string) $v1->attributes()->value;
            else if($v1->attributes()->name == "ga:profileId")
                $profileId = (string) $v1->attributes()->value; 
        }

        echo "profile id ".$profileId;

        echo "<BR>";    

        echo "acctName ".$acctName;

        echo "<BR>";    

        $subArray = array($acctName => $profileId);

        print_r($subArray);

        $arr[] = array($acctId => $subArray);

    }

    print_r($arr);

    return json_encode($arr);

}

The most important bit is where I print_r subArray. I can see acctName and profileId print, but then subArray is empty. For Example:

profile id 45580
acctName accountName1
Array
(
)
profile id 4300
acctName accountName2
Array
(
)
profile id 4338
acctName accountName3
Array
(
)

How are these values not being inserted? I’ve been looking at the code for a while now, and I’m a bit confused.

Any suggestions would really help,
Thanks!

  • 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-23T14:29:28+00:00Added an answer on May 23, 2026 at 2:29 pm

    $v->title is actually a SimpleXMLObject still!

    I forgot to cast it as a string, when I tried to make it the index in the array, it freaked out, geez I spent a whole hour on this!

    Thanks for your suggestions guys 😛

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

Sidebar

Related Questions

I'm trying to build a tool to average values from a multidimensional array in
I'm trying to build a UNION query using Kohana's query builder . Everything works
I am trying to build a function in C/C++ to sort an array and
I am trying to build out a useful 3d game engine out of the
I'm having trouble trying to build an array in PHP which will output in
I'm trying to build an array structured like [ [num, [num, num num]], [num,
I'm trying to build a multidimensional associative array while fetching the results from a
I am trying to build a php function that would return an array with
I'm trying to build a C++ extension for python using swig. I've followed the
I am trying to build an 2D array with the size of from 1D

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.