V
V
Vitaly Mironov2018-06-27 13:08:48
PHP
Vitaly Mironov, 2018-06-27 13:08:48

How to convert a string to an object?

How to translate an object as a string into a real object?
Example string (print_r array):

stdClass Object
(
    [array] => Array
        (
            [0] => 1
            [1] => 2
            [2] => 3
        )

    [boolean] => 1
    [null] => 
    [number] => 123
    [object] => stdClass Object
        (
            [a] => b
            [c] => d
            [e] => f
        )

    [string] => Hello World
)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2018-06-27
@nor1m

1. This is not an array, but an object
2. I think entropy will interfere with us here, you can’t make mashed potatoes with a cutlet out of poop back.
3. If the structure is simple and the same, then it is possible to collect an array from this string with regular expressions.
Where did this line come from? Perhaps it is worth solving the issue of forming a more convenient string, for example json, what would then be assembled back into one line of code without dancing with a tambourine?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question