You need to change the values in this codes
define('TO_SHOW',7); // number of items to show in your case it is 7
$selected = 1; //// which one you need need at center.
和你的阵列;
执行此操作并尝试:
<?php
define('TO_SHOW',7); // number of items to show in your case it is 7
function change_order($arry, $sel){
$arr_cnt = count($arry);
$shift_count = $arr_cnt - (ceil(TO_SHOW/2)-$sel);
for($i=0; $i<$shift_count; $i++){
array_push($arry, array_shift($arry));
}
return array_slice($arry, 0, TO_SHOW);
}
$arr = array(array(
"id" => 1,
"date" => 2012-09-29
),
array(
"id" => 2,
"date" => 2012-09-29
),
array(
"id" => 3,
"date" => 2012-09-29
),
array(
"id" => 4,
"date" => 2012-09-29
),
array(
"id" => 5,
"date" => 2012-09-29
),
array(
"id" => 6,
"date" => 2012-09-29
),
array(
"id" => 7,
"date" => 2012-09-29
),
array(
"id" => 8,
"date" => 2012-09-29
),
array(
"id" => 9,
"date" => 2012-09-29
),
array(
"id" => 10,
"date" => 2012-09-29
),
array(
"id" => 11,
"date" => 2012-09-29
),
array(
"id" => 12,
"date" => 2012-09-29
),
array(
"id" => 13,
"date" => 2012-09-29
),
array(
"id" => 14,
"date" => 2012-09-29
)
);
$selected = 1; //// centre one
$test = change_order($arr, $selected);
echo "<pre>";
print_r($test);
?>