Problem in getting multidimensional array from simple xml object

Posted by Rishi2686 on Stack Overflow See other posts from Stack Overflow or by Rishi2686
Published on 2010-05-26T07:14:22Z Indexed on 2010/05/26 8:21 UTC
Read the original article Hit count: 245

Filed under:
|
|

Hi there, As a newbie I need your help in getting multidimensional array from simplexml object. suppose my array is like: just for getting idea:
Here $data is a simplexml object contains below xml:

<users>
  <user>
    <id></id>
    <nm></nm>
    <gender>
      <male></male>
      <female></female>
    </gender>
  </user>
</users>

Here I an perfectly getting array of each user, but in that array when it comes to gender, it shows nothing. i need array of gender too. I am using following code:

foreach($data->users as $users)
{
  $arr1 = array();
  foreach($users as $user)
  {
    foreach($user as $k=>$v)
    {
      $arr1[$k] = (string) $v;
    }
  }
  $arr2[] = $arr1;
}

Any suggestion?

© Stack Overflow or respective owner

Related posts about php

Related posts about array