skip to Main Content

In a DB table from wordpress (Caldera Form plugin), there’s a JSON array as value, and from a query, result has this structure :

Array (
    [0] => stdClass Object (
        [config] => a:22:{
            s:2:"ID";
            s:15:"CF605df92fa7a17";
            s:13:"_last_updated";
            s:31:"Sat, 27 Mar 2021 16:44:15 +0000";
            s:10:"cf_version";
            s:5:"1.9.4";
            s:4:"name";
            s:29:"Registration for Artists 2021";
            s:10:"scroll_top";...}
        ) 
    [1] => stdClass Object (
        [config] => a:22:{
            s:2:"ID";
            s:15:"CF605ba79300239";
            s:13:"_last_updated";
            s:31:"Sat, 27 Mar 2021 16:44:51 +0000";
            s:10:"cf_version";
            s:5:"1.9.4";
            s:4:"name";
            s:29:"Inscription des Artistes 2021";
            s:10:"scroll_top";...}
        ) 

How can i read "a:22" then "s:15" inside ?
I done a json_decode with [config] value but it return a empty value..

2

Answers


  1. Chosen as BEST ANSWER

    you put me on the track

    $results = [];
    $data = [];
    foreach ($entries as $key => $object) {
    
        $results[] = unserialize($object->config);
        foreach ($results as $key => $value) {
            $data = [
                'id' => $value['ID'],
                'name' => $value['name']
            ];
        }
    
        var_dump($data);
    
    }```
    
    gives :
    
    array(2) { ["id"]=> string(15) "CF605df92fa7a17" ["name"]=> string(29) "Registration for Artists 2021" } 
    array(2) { ["id"]=> string(15) "CF605ba79300239" ["name"]=> string(29) "Inscription des Artistes 2021" } 
    
    It's what i need
    So I can continue
    Thanxs
    

  2. Using this array dump you posted, what does this return?

    foreach ($array as $key => $object) {
    
        $config = unserialize($object->config);
    
        var_dump($config);
    
    }
    

    Pass the same variable you dumped through $array. This might not work but worth a shot.


    For example, if I have this $array dumped data…

    Array
    (
        [0] => stdClass Object
            (
                [config] => a:4:{s:2:"ID";s:15:"CF605df92fa7a17";s:13:"_last_updated";s:31:"Sat, 27 Mar 2021 16:44:15 +0000";s:10:"cf_version";s:5:"1.9.4";s:4:"name";s:29:"Registration for Artists 2021";}
            )
    
        [1] => stdClass Object
            (
                [config] => a:4:{s:2:"ID";s:15:"CF605ba79300239";s:13:"_last_updated";s:31:"Sat, 27 Mar 2021 16:44:51 +0000";s:10:"cf_version";s:5:"1.9.4";s:4:"name";s:29:"Inscription des Artistes 2021";}
            )
    
    )
    

    And run the above unserialize() function in loop, this is the output…

    Array
    (
        [ID] => CF605df92fa7a17
        [_last_updated] => Sat, 27 Mar 2021 16:44:15 +0000
        [cf_version] => 1.9.4
        [name] => Registration for Artists 2021
    )
    Array
    (
        [ID] => CF605ba79300239
        [_last_updated] => Sat, 27 Mar 2021 16:44:51 +0000
        [cf_version] => 1.9.4
        [name] => Inscription des Artistes 2021
    )
    


    Response to your last comment, what does this output… ?

    foreach ($array as $key => $object) {
    
        var_dump($object);
    
        // $config = unserialize($object->config);
    
        // var_dump($config);
    
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search