-2
$header_content = array();
$header_content['pageone'][] = array(
    'image' => 'photo-one.png',
    'desc'  => "One. Some text here.",
);
$header_content['pagetwo'][] = array(
    'image' => 'photo-two.png',
    'desc'  => "Two. Some text here.",
);

I do not want to echo the entire array, just certain parts when called... like $header_content['pageone']['image'], except this doesn't work... How do you go about echoing parts of an array?

I have searched but it's all a little confusing right now for me. Thanks.

Matthew
  • 673
  • 1
  • 7
  • 16

3 Answers3

1

Define it like -

$header_content['pagetwo'] = array(
'image' => 'photo-two.png',
'desc'  => "Two. Some text here.",
);

The keys are different pageone, pagetwo. No need of that extra index i think. And then access it - echo $header_dontent['pagetwo']['image'];

Sougata Bose
  • 31,517
  • 8
  • 49
  • 87
1

For printing array values, you can use :

print_r function

Example : print_r($array) Specific key data can be accessed through : print_r($array[$key])

OR

var_dump function

Example : var_dump($array) Specific key data can be accessed through : var_dump($array[$key])

Community
  • 1
  • 1
Praveen Dabral
  • 2,449
  • 4
  • 32
  • 46
1

use it like $header_content['pageone'][0]['image']
Since

$header_content['pageone'][] = array();

[] appends an element at the end of an array.

Raja
  • 851
  • 9
  • 22