php - 如何输出数组的值
问题描述
我是 PHP 的完整初学者。但是我知道如何输出自定义字段的值。我对数组有一些问题。后元键是fw_options
. 该值有多个数组,如下所示:
array (
0 =>
array (
'featured_post' => false,
'featured_expiry' => '',
'_featured_book_string' => '0',
'reading_level' => 'medium',
'reading_type' =>
array (
'time' => 'fixed',
'hourly' =>
array (
'hourly_read' => '',
'estimated_hours' => '',
),
'fixed' =>
array (
'reading_times' => '500',
),
),
'reading_duration' => 'one_month',
'english_level' => 'fluent',
'readers_level' => 'starter',
'expiry_date' => '2019/12/31',
'show_attachments' => 'off',
'read_documents' =>
array (
),
'address' => '',
'longitude' => '',
'latitude' => '',
'country' =>
array (
0 => '717',
),
),
)
我有这段代码,我试过但没有成功:
$array = get_post_meta( get_the_ID(), 'fw_options', true );
echo $array[0]['reading_type']['fixed']['reading_times'];
如何500
从 post meta key输出值reading_times
?
解决方案
简单根据键打印数组先将值保存到变量中,然后根据数组键打印
$data = array(
'featured_post' => false,
'featured_expiry' => '',
'_featured_book_string' => '0',
'reading_level' => 'medium',
'reading_type' =>
array(
'time' => 'fixed',
'hourly' =>
array(
'hourly_read' => '',
'estimated_hours' => '',
),
'fixed' =>
array(
'reading_times' => '500',
),
),
'reading_duration' => 'one_month',
'english_level' => 'fluent',
'readers_level' => 'starter',
'expiry_date' => '2019/12/31',
'show_attachments' => 'off',
'read_documents' =>array(),
'address' => '',
'longitude' => '',
'latitude' => '',
'country' =>
array(
0 => '717',
),
);
echo $data['reading_type']['fixed']['reading_times'];
输出# 500
推荐阅读
- reactjs - 在 Simulate('change') 状态未更新后
- azure - Azure 获取多租户中的所有组织
- hibernate - 在 tomcat 中创建名为“dataSource”的 bean 时出错
- python - 未找到关闭的属性
- android - 清空 Singleton 实例和所有字段
- angular - 如何对表单内的指令进行验证?
- android - 动画不听 onRepeatAnimation 函数
- c# - 我不明白 Ninject 如何在我的应用程序 MVC 中创建 RoleManager
- sql - 如何将sql任务中以下查询的结果集分配给ssis中的变量
- fullcalendar - 自定义按钮切换设置 filterResourcesWithEvents 忽略 jquery text() 调用