0
我從var_export($post_meta);
的結果從$post_meta = get_post_meta(80)
得到以下數組;在多維陣列上的filter_input_array
array (
'_edit_last' =>
array (
0 => '1',
),
'_edit_lock' =>
array (
0 => '1451326767:1',
),
'_sidebar' =>
array (
0 => 'Kies Sidebar',
),
'_wp_page_template' =>
array (
0 => 'page-pop.php',
),
'custom_sidebar_per_page' =>
array (
0 => 'default',
),
'_cat_id' =>
array (
0 => '21',
),
'_order_by' =>
array (
0 => 'date',
),
'_asc' =>
array (
0 => 'DESC',
),
'_post_count' =>
array (
0 => '5',
),
'_days' =>
array (
0 => '0',
),
'_custom_sidebar_per_page' =>
array (
0 => 'default',
),
)
現在我需要過濾一些這些值,如果他們存在,所以我可以安全地使用它們。我做了以下
$args = [
'_cat_id' => [
0 => [
'filter' => FILTER_VALIDATE_INT,
'default' => 1
]
],
'_page_title' => [
0 => FILTER_SANITIZE_STRING,
],
'_posts_title' => [
0 => FILTER_SANITIZE_STRING,
],
'_order_by' => [
0 => [
'filter' => FILTER_SANITIZE_STRING,
'default' => 'date'
]
],
'_asc' => [
0 => [
'filter' => FILTER_SANITIZE_STRING,
'default' => 'DESC'
]
],
'_post_count' => [
0 => [
'filter' => FILTER_VALIDATE_INT,
'default' => get_option('posts_per_page')
]
]
];
$meta = filter_var_array($post_meta, $args);
,但我從var_export($meta)
array (
'_cat_id' => false,
'_page_title' => NULL,
'_posts_title' => NULL,
'_order_by' => false,
'_asc' => false,
'_post_count' => false,
)
東西得到下面的結果像_cat_id
應該得到的數組中返回類似
'_cat_id' =>
array (
0 => 21,
),
。
如何多維數組上使用filter_var_array
任何想法
或許這可以幫助?看起來像filter_var_array不能遞歸工作。 http://stackoverflow.com/questions/4829355/filter-var-array-multidimensional-array – eol