值$psabad1
为(i:169;i:170;i:173)
;这是序列化的。我想将此值转换为(169,170,173)
。在此代码中,只返回第一个值(169)
,而我想返回所有值(169,170,173)
$stmt1 = $db->prepare("SELECT `psabad`,`transId`,`pardakht` FROM `orders` WHERE `transId`=?");
$stmt1->bind_param("s", $transId);
$stmt1->execute();
$stmt1->store_result();
$stmt1->bind_result($psabad1, $transid1, $pardakht1);
while ($stmt1->fetch()) {
$pardakht = unserialize($psabad1);
$stmt2 = $db->prepare("SELECT `idsabad`,`idmahsool`,sabad.tedad, sabad.pardakht, pack2.titr, pack2.brand FROM `sabad` INNER JOIN pack2 ON pack2.id = sabad.idmahsool WHERE `idsabad`=?");
$stmt2->bind_param("i", $pardakht);
$stmt2->execute();
$stmt2->store_result();
$stmt2->bind_result($idsabad2, $idmahsool2,$tedad2, $pardakht2, $titr2, $brand2 );
$stmt2->fetch();
echo $titr2;
}
答案 0 :(得分:0)
您的输出看起来很奇怪。通常,序列化数据如下所示:
a:9:{i:0;i:1;i:1;i:2;i:2;i:3;i:3;i:4;i:4;i:5;i:5;i:6;i:6;i:7;i:7;i:8;i:8;i:9;}
如果您的数据看起来与标题中的内容完全相同,如下面的$ s所示,您可以使用这个小函数检索数组:
<?php
$a = [1,2,3,4,5,6,7,8,9];
$s = 'i:1;i:2;i:3;i:4;i:5;i:6;i:7;i:8;i:9;';
var_dump($a === _unserialize($s));
function _unserialize($s){
$i = 0;
$_s = '';
foreach(explode(';', trim($s, '()')) as $part){
if($part != ''){
$_s .= 'i:' . ($i++) . ';' . $part . ';';
}
}
return unserialize('a:' . $i . ':{' . $_s . '}');
}
?>
输出:
..\php\php5.6\php.exe serialize.php
bool(true)