I need an associative array of the basic structure
$digest = {
'subscriptions' => [
{ 'time' => 0825,
'company' => "Facebook",
},
{ 'time' => 0930,
'company' => "Twitter",
}
],
'notifications' => [
'user' = 'djechlin',
'items' => [
{ 'message' => "Happy Birthday!",
},
],
],
}
How best to implement this sort of thing in PHP? Do I make a series of classes that nest in an obvious fashion? Can I do this in one shot? I'm trying to emulate some small degree of type-safety here coming from a C++/C/Java background. Or do I just have to manage everything as associate arrays defined throughout the code and hope the structures that are passed match up and all?
If you replace every {
and [
in your code with array(
, and each }
and }
with )
, you will have a working PHP implementation.
PHP is not a type-safe language, so trying to use classes here to enforce type safety will just lead to a bunch of extra typing, and eventual disappointment.