Question: I want to return an array containing the keys:

```
<?php
if(isset($values[0]->Content)):
$jarray= json_decode($values[0]->Content);
print_r(array_keys($jarray));
exit;
endif;
?>

```

Output of `$jarray`:

```
stdClass Object
(
    [_token] => QjyTAyDDUeadYvO0qj0gAZyK7OVyudSsY7Sq8Hhp
    [datefrom] => 2017-07-07
    [dateto] => 2017-07-31
    [Productivity] => test1
    [Productivityrating] => 2
    [Technical_Skills] => test2
    [Technical_Skillsrating] => 3
    [Work_Consistency] => test3
    [Work_Consistencyrating] => 4
    [Presentation_skills] => test4
    [Presentation_skillsrating] => 5
    [test] => test5
    [testrating] => 3
    [cycle_id] => 1
    [save] => proceed
)

```

I want to return an array containing the keys so i tried

```
array_keys($jarray)

```

but it gives an error like 

> 
> array\_keys() expects parameter 1 to be array, object given (View:
>  my path)
> 
> 
> 

Expected output:

```
Array
(
    [0] =>_token
    [1] => datefrom
    [2] =>_dateto
    [3] => Productivity
    [4] =>Productivityrating
    [5] => Work_Consistency
    [6] =>_Work_Consistencyrating

)etc

```

Any help would be appreciated.

Answer: 
For each element, you can get the namespaces associated with it. This is an array such as 

```
Array
(
    [admin] => someval
)

```

So you need to extract the first key from this to get the namespace of the element...

```
    foreach ($xpath as $child)
    {
        $arr[] = array_keys($child->getNameSpaces())[0].':'.$child->getName();
    }
    echo '<pre>'; 
    print_r($arr);

```

Gives...

```
<pre>Array
(
    [0] => admin:a
    [1] => admin:b
    [2] => system:c
    [3] => links:d
)

```
The "someval" values are the real namespaces. "admin", "system" and "links" are only aliases/prefixes in the document. They are optional and can change on ANY element node.

Register your own prefix for the namespace, use the prefix in your Xpath expressions.

```
$xml = <<<'XML'
<?xml version="1.0" encoding="US-ASCII" ?>
<main:docs xmlns:main="urn:main" xmlns:admin="urn:admin" xmlns:system="urn:system" xmlns:links="urn:links">
    <admin:a>value</admin:a>
    <admin:b>value</admin:b>
    <system:c>value</system:c>
    <links:d>value</links:d>
</main:docs>
XML;

$xmlns = [
  'm' => "urn:main",
  'a' => "urn:admin",
  's' => "urn:system",
  'l' => "urn:links", 
];

$mainDocs = new SimpleXMLElement($xml);
foreach ($xmlns as $prefix => $namespace) {
  $mainDocs->registerXpathNamespace($prefix, $namespace);
}

$docChildren = $mainDocs->xpath('//m:docs/*');

$array = [];
foreach ($docChildren as $child) {
    $array[] = $child->getName();
}

echo var_dump($array);

```