0

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?

djechlin
  • 59,258
  • 35
  • 162
  • 290
  • I don't know PHP well enough to ask anything more specific. I need some guidance here. So, let's go with "yes" or "maybe" and it would be great if you would explain how to do that. – djechlin May 24 '12 at 23:32
  • Super easy once you get used to it: http://php.net/manual/en/language.types.array.php – Jeff Hines May 24 '12 at 23:54

1 Answers1

1

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.