我已在数据库中序列化值,我从数据库中获取它们然后当我
时<pre>
print_r($DataValues)
</pre>
它显示了我这样的价值
[0] => stdClass Object
(
[categories] => a:1:{i:38;s:21:"Summer Market Session";}
)
[1] => stdClass Object
(
[categories] => a:1:{i:38;s:21:"Summer Market Session";}
)
[2] => stdClass Object
(
[categories] => a:2:{i:38;s:21:"Summer Market Session";i:39;s:21:"Autumn Market Session";}
)
我希望在反序列化之后只获取值,我试图反序列化但是显示bolean false
&安培;当我尝试在为每个值运行后打印该值时,它会向我显示下面提到的错误
捕获致命错误:类stdClass的对象无法转换为字符串
我不知道我是怎么做到这一点我正在尝试所有我所知道的非序列化战术&amp;我也尝试使用foreach循环在数组中存储值,但我失败了..
请帮助我如何在取消它后获得它的价值...... ??
答案 0 :(得分:2)
好吧,不知怎的,我还是看不出问题。我已经重建了你似乎从DB得到的数据结构:
$testObject = new stdClass();
$testCategories = array(38 => 'Summer Market Session');
$testObject->categories = serialize($testCategories);
$anotherTestObject = new stdClass();
$anotherTestCategories = $testCategories;
$anotherTestCategories[] = 'Autumn Market Session';
$anotherTestObject->categories = serialize($anotherTestCategories);
$dataValues = array(
$testObject, clone $testObject, $anotherTestObject
);
print_r($dataValues);
它给了我你在问题中引用的相同输出,所以我猜这是正确的重建。要打开这些数据,简单的循环就足够了:
foreach ($dataValues as $dataElement) {
$categories = unserialize($dataElement->categories);
print_r($categories);
}
或者我做错了什么?
无论如何,这里有a sandbox来检查这一切。