Вы можете сделать это разными способами, поищите различные подходы и их демонстрационные примеры.
Используя extract()
,
<?php
$str = '{"Confirmation":"200710035843DH4","Message":"success","Status":"success"}';
extract(json_decode($str,true));
echo $Confirmation;
?>
DEMO: https://3v4l.org/3U43b
Использование foreach()
,
<?php
$str = '{"Confirmation":"200710035843DH4","Message":"success","Status":"success"}';
$array = json_decode($str,true);
foreach ( $array as $key => $value ) { $$key = $value; }
echo $Confirmation;
?>
ДЕМО: : https://3v4l.org/jLnRE
Использование array destructure
(начиная с php 7.1 ),
<?php
$str = '{"Confirmation":"200710035843DH4","Message":"success","Status":"success"}';
['Confirmation'=>$confirmation, 'Message'=>$message, 'Status'=>$status] = json_decode($str,true);
echo $confirmation;
?>
ДЕМО: https://3v4l.org/rrFa8
Использование list()
,
<?php
$str = '{"Confirmation":"200710035843DH4","Message":"success","Status":"success"}';
list('Confirmation'=>$confirmation, 'Message'=>$message, 'Status'=>$status) = json_decode($str,true);
echo $confirmation;
?>
ДЕМО: https://3v4l.org/Zpt60