PHP 展开不同元素之间的特定文本

PHP explode specific text beetwen different elements

我有结果

{"success":true,"data":{"id":6583879,"listingId":"11745/3470/OMS"}}

我需要在两个数组上展开它:

$id = 6583879;

$listid = 11745/3470/OMS

我想避免计算字符数,此回复可能会在以后出现。我正在考虑参加:

只需解码 json 数据

$data = '{"success":true,"data":[{"id":6583879,"listingId":"11745/3470/OMS"}]}';

$arr = json_decode($data);
$id = array();
$listing = array();


for($i=0; $i < count($arr->data); $i++){
    $id[$i] = $arr->data[$i]->id;
    $listing[$i] = $arr->data[$i]->listingId;
}

//loop array to view data
foreach($id as $value){
   echo $value.'<br>';
}

?>

PHP code demo

<?php
$json='{"success":true,"data":{"id":6583879,"listingId":"11745/3470/OMS"}}';
$array=  json_decode($json,true);
extract($array["data"]);
$first=array("id"=>$id);
$second=array("listingId"=>$listingId);
print_r($first);
print_r($second);

输出:

Array
(
    [id] => 6583879
)
Array
(
    [listingId] => 11745/3470/OMS
)
<?php
$json='{"success":true,"data":{"id":6583879,"listingId":"11745/3470/OMS"}}';
$decoded = json_decode($json);
$id = $decoded['data']['id'];
$listingId = $decoded['data']['listingId'];