【发布时间】:2009-12-17 03:42:35
【问题描述】:
我在 PHP 中有一个 Shift 对象数组。我需要将这些对象存储在数据库中。我正在开发一个向数据库添加班次的函数:
$Serialized_S = get_option('MasterShiftString');
$MasterShiftArray = unserialize($Serialized_S);
if(!$MasterShiftArray)
{
echo "MasterShiftArray returns false";
}//end if
echo "Serialized_S:";
print_r($Serialized_S);
echo "<br />MasterShiftString:";
print_r($MasterShiftString);
echo "<br />end<br />";
if(!is_array($MasterShiftArray))
{
echo "MasterShiftArray is not an Array....";
$MasterShiftArray = array($last_monday_from_date => "");
}//end if
else
{
}//end else
$WeekShiftArray = $MasterShiftArray;
array_push($WeekShiftArray, $CurrentShift);
$MasterShiftArray[$last_monday_from_date] = $WeekShiftArray;
$Serialized_s = serialize($MasterShiftArray);
update_option('MasterShiftArray', $Serialized_s);
当然,当我执行这个时我得到的是:
last_monday_from_date: 1260777600
MasterShiftArray returns falseSerialized_S:admin,resource,2,1;admin,resource,2,1;admin,resource,2,1;admin,resource,2,1;
MasterShiftString:
end
我在这里做错了什么?我已经尝试过 base64 编码,但这无济于事。 MasterShiftArray 不是数组......
【问题讨论】:
标签: php serialization