【发布时间】:2014-03-10 17:12:17
【问题描述】:
我想知道是否有一种干净的方法来切片数组 WITH 位置条件,以便(例如)每个第五个元素将被删除,而 Vice Versa(例如)只选择第五个元素。
<?php
$input = array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m");
print_r ( array_slice ( $input, 0, count($input) ) ); //works but not what I need.
// This is not the correct syntax but just to get the idea
// print_r ( array_slice ( $input, 0, count($input) ) , {ONLY IF POSITION IS NOT MOD 5 SO 5,10,15,20,25 ... (ETC) WILL BE DROPPED} );
// AND VICE VERSA
// print_r ( array_slice ( $input, 0, count($input) ) , {ONLY IF POSITION IS MOD 5 SO IT WILL SELECT POSITION 5,10,15,20,25 ... (ETC) } );
?>
如果没有用于该任务循环的专用 php 命令就可以了 :)
谢谢!
【问题讨论】:
-
你需要什么格式?你能详细说明一下吗?