如何将String Array转换为Real数组PHP

screenshot

Hello, as you can see in the screenshot, when i extract data from a site with PHP Simple HTML DOM Parser. I have this result , so i would like to convert this data to a real array to have the real control and the opportunity to access with $array['label']

<?php include_once('simple_html_dom.php'); ?>
<!DOCTYPE html>

<html>
<head>

<title> HTML DOM Parser</title>
</head>
<body>
<?php
header('Content-Type: text/html; charset=utf-8');
set_time_limit(0);
$html=file_get_html('https://www.monreseauplus.com/villes/');
$array[]=array();
$array3[]=array();
foreach($html->find('.ul. li.cat-item a') as $elements){
    $array2=$elements->title;
    $array=str_replace(':','=>',$array2);
    $arraynospec=htmlspecialchars_decode($array);
    var_dump($arraynospec);
    }
?>
</body>
</html>

So it looks like you are trying to string manipulate JSON to try to make some sort of associative array. Replacing the : with => is not the right move here...

    <?php include_once('simple_html_dom.php'); ?>
    <!DOCTYPE html>

    <html>
    <head>

    <title> HTML DOM Parser</title>
    </head>
    <body>
    <?php
    header('Content-Type: text/html; charset=utf-8');
    set_time_limit(0);
    $html=file_get_html('https://www.monreseauplus.com/villes/');
    $array[]=array();
    $array3[]=array();
    foreach($html->find('.ul. li.cat-item a') as $elements){
        $array2=$elements->title;
        $array=json_decode($array2,true)
        $arraynospec=htmlspecialchars_decode($array);
        var_dump($arraynospec);
    }
    ?>
    </body>
    </html>

Try that

This is the problem: $array=str_replace(':','=>',$array2); Looks like it was already in JSON!