Php Preg请输入json多维字符串
我有这样的字符串:Php Preg请输入json多维字符串,php,json,Php,Json,我有这样的字符串: <?php echo $str_is; ?> $thearray["id_is"]="'bG1saW50YXMgbWFoYWthbTMyMTI'" $thearray["date_is"]="'2015-2-25'" 我需要得到如下数组: <?php echo $str_is; ?> $thearray["id_is"]="'bG1saW50YXMgbWFoYWthbTMyMTI'" $thearray["date_is"]="'2015-2-2
<?php
echo $str_is;
?>
$thearray["id_is"]="'bG1saW50YXMgbWFoYWthbTMyMTI'"
$thearray["date_is"]="'2015-2-25'"
我需要得到如下数组:
<?php
echo $str_is;
?>
$thearray["id_is"]="'bG1saW50YXMgbWFoYWthbTMyMTI'"
$thearray["date_is"]="'2015-2-25'"
我尝试使用(im新手使用代码preg_match):
这将是一种方法:
$str_is = <<< EOS
[["id_is","'bG1saW50YXMgbWFoYWthbTMyMTI'"],["date_is","'2015-2-25'"]]
EOS;
// Convert the JSON string to an array
$array = json_decode($str_is, true);
// Loop the array adding to $thearray
foreach ($array as $pair) {
// First element = key (e.g. "id_is")
// Second element = value (e.g. "'bG1saW50YXMgbWFoYWthbTMyMTI'")
$thearray[$pair[0]] = $pair[1];
}
echo $thearray['id_is'], PHP_EOL;
echo $thearray['date_is'], PHP_EOL;
'bG1saW50YXMgbWFoYWthbTMyMTI'
'2015-2-25'