我们在尝试将函数生成的多个值插入数组时遇到了麻烦。当我们使用字符串打印函数并手动复制结果时,它可以工作,但是当我们尝试使用字符串使其工作到数组中时,它就不行了。
<?php
function dateRange( $first, $last, $step = '+1 day', $format = 'm/d/Y' ) {
$current = strtotime( $first );
$last = strtotime( $last );
while( $current <= $last ) {
$dates .= "'" . date( $format, $current) . "', ";
$current = strtotime( $step, $current );
}
return $dates;
}
$all_dates = dateRange( '01/20/1999', '01/23/1999');
echo $all_dates; /* PRINTS ALL DATES BETWEEN TWO DATES: '01/20/1999', '01/21/1999', '01/22/1999', '01/23/1999', */
query_posts( array(
'post_type' => 'bbdd',
'meta_query' => array(
$location,
array(
'key' => 'date',
'value' => array($all_dates), /* DOESN'T WORK. INSTEAD, IF WE COPY THE RESULT OF "echo $all_dates;" MANUALLY, IT DOES WORK */
),
)
) );
?>