views:

59

answers:

1

I have an array of Shift objects that I'm working with in PHP. I need to store these objects within a database. I'm working on a function that will add shifts to the database:

$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);

Of course what I'm getting when I execute this is:

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

What am I doing wrong here? I've tried the base64 encoding, but that doesn't do anything to help. MasterShiftArray is not an Array....

+1  A: 

This:

admin,resource,2,1;admin,resource,2,1;admin,resource,2,1;admin,resource,2,1

looks nothing at all like a PHP serialized array, that's your problem. Garbage in = garbage out.

Assuming that's the data format you need to deal with, look into using explode to break it into an array on ';', then explode each member of that array on ','.

Don Neufeld
What is it doing then?
Sakamoto Kazuma
OMG ... I'm sorry .... I feel like a complete idiot now... I put in the wrong var.
Sakamoto Kazuma