views:

44

answers:

2

Ok I have a mult-dimensional array which has the following structure...

  0 => 
  array (
    'membership' => 
    array (
      'member' => 
      array (
        'name' => '',
        'landline' => '',
        'libcard' => '',
        'mobile' => '',
        'email' => '',
      ),
      'updated_at' => '',
      'member_id' => 12345,
      'starts_at' => '',
      'id' => 14,
      'group_id' => 280,
      'optional_field_values' => 
      array (
        0 => 
        array (
          'optional_field' => 
          array (
            'name' => '',
            'updated_at' => '',
            'id' => 1,
            'group_id' => 280,
            'description' => '',
            'created_at' => '',
          ),
          'updated_at' => '',
          'optional_field_id' => 1,
          'membership_id' => 14,
          'id' => 4,
          'value' => '12539267',
          'created_at' => '',
        ),
      ),
      'ends_at' => '',
      'joining_fee' => 0,
      'created_at' => '',
    ),
   ),

Now I can access everything inside Membership and inside Member using code like...

$member[0]['membership']['member']['name']
or 
$member[0]['membership']['joining_fee']

But when ever I try to access stuff inside optional_field_values I get nothing returned...

Any ideas why this is not working?

Edit:

Trying to access the field using code like...

$member[0]['membership']['optional_field_values']['value']
+2  A: 
$member[0]['membership']['optional_field_values'][0]['value']

^ Should work...

(Edited to match OP's edit)

chigley
ZING! That works now, didn't realise I would need a [0] in it.
Aran
@Aran - check my edit, now I know what value you're after. (You'd missed out the `[0]`)
chigley
+2  A: 

How about :

$member[0]['membership']['optional_field_values'][0]['value']

You can iterate over all optional field values like this :

foreach ($member[0]['membership']['optional_field_values'] as $field)
   echo $field['value'];
giraff