0

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 Answer 1

1

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 ','.

Sign up to request clarification or add additional context in comments.

1 Comment

OMG ... I'm sorry .... I feel like a complete idiot now... I put in the wrong var.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.