Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    2
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Extracting a value from a multidimensional array

    I'm sure this is one of those easy queries that I'm making harder! I am using an array that looks like this:
    Code:
    $meta_boxes[] = array(
    	'id' => 'person_meta_box',
    	'fields' => array(
    		array(
    			'name' => 'Born:',
    			'id' =>  'date_of_birth'
    		),
    		array(
    			'name' => 'Died:',
    			'id' =>  'date_of_death'
    		)		
    
    	)
    );
    I am getting into a twist over how to get the field 'name' into a variable to echo to the screen. Can you help? (Sadly, simplifying the data structure is not possible!)

  • #2
    Regular Coder
    Join Date
    Jul 2006
    Posts
    399
    Thanks
    33
    Thanked 7 Times in 7 Posts
    PHP Code:
    $meta_boxes = array(
        
    'id' => 'person_meta_box',
        
    'fields' => array(
            array(
                
    'name' => 'Born:',
                
    'id' =>  'date_of_birth'
            
    ),
            array(
                
    'name' => 'Died:',
                
    'id' =>  'date_of_death'
            
    )

        )
    );

    echo 
    $meta_boxes["fields"][0]["name"]; 

  • Users who have thanked sybil6 for this post:

    nickp (11-16-2010)

  • #3
    Regular Coder poyzn's Avatar
    Join Date
    Nov 2010
    Posts
    266
    Thanks
    2
    Thanked 61 Times in 61 Posts
    for field name = Born it will be:
    PHP Code:
    $var $meta_boxes[0]['fields'][0]['name'];
    echo 
    $var

  • Users who have thanked poyzn for this post:

    nickp (11-16-2010)

  • #4
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    2
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thank you both - you've got me over a blank spell this morning!


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •