$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?
我不想回显整个数组,只是调用某些部分...比如$ header_content ['pageone'] ['image'],除了这不起作用...你如何回应部分的阵列?
I have searched but it's all a little confusing right now for me. Thanks.
我已经搜索过但现在对我来说有点混乱。谢谢。
3 个解决方案
#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'];
键是不同的pageone,pagetwo。我认为不需要额外的指数。然后访问它 - echo $ header_dontent ['pagetwo'] ['image'];
#2
For printing array values, you can use :
要打印数组值,您可以使用:
Example : print_r($array) Specific key data can be accessed through : print_r($array[$key])
示例:print_r($ array)可以通过以下方式访问特定的密钥数据:print_r($ array [$ key])
OR
Example : var_dump($array) Specific key data can be accessed through : var_dump($array[$key])
示例:var_dump($ array)可以通过以下方式访问特定的密钥数据:var_dump($ array [$ key])
#3
use it like $header_content['pageone'][0]['image']
Since
像$ header_content ['pageone'] [0] ['image']一样使用它
$header_content['pageone'][] = array();
$ header_content ['pageone'] [] = array();
[]
appends an element at the end of an array.
[]在数组的末尾附加一个元素。
#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'];
键是不同的pageone,pagetwo。我认为不需要额外的指数。然后访问它 - echo $ header_dontent ['pagetwo'] ['image'];
#2
For printing array values, you can use :
要打印数组值,您可以使用:
Example : print_r($array) Specific key data can be accessed through : print_r($array[$key])
示例:print_r($ array)可以通过以下方式访问特定的密钥数据:print_r($ array [$ key])
OR
Example : var_dump($array) Specific key data can be accessed through : var_dump($array[$key])
示例:var_dump($ array)可以通过以下方式访问特定的密钥数据:var_dump($ array [$ key])
#3
use it like $header_content['pageone'][0]['image']
Since
像$ header_content ['pageone'] [0] ['image']一样使用它
$header_content['pageone'][] = array();
$ header_content ['pageone'] [] = array();
[]
appends an element at the end of an array.
[]在数组的末尾附加一个元素。