L
L
lexstile2021-06-10 22:54:00
PHP
lexstile, 2021-06-10 22:54:00

Why does a primitive turn into an object?

Data is coming:

print_r($obj);

SimpleXMLElement Object
(
    [id] => 1082930
    [state] => REGISTERED
)

I need to take id from $obj and make a new request with parameters:
$params = [
    'sector' => SECTOR_ID,
    'id' => $obj->id,
    'client_ref' => $user->client_ref,
  ];

I do:
print_r($params);

Array
(
    [sector] => 2721
    [id] => SimpleXMLElement Object
        (
            [0] => 1082930
        )

    [client_ref] => test
)

I do:
echo $obj->id;

# результат
1082930

Why do I get an object in the first case?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question