2017-01-02 9 views
0

1分ごとに配列を取得するにはどうすればよいのですか?phpは1分ごとに配列の一部だけを取得します

まず分取得:21
4分アレイ30:11
3分分〜20:1の取得秒分
10に、例えば

、31 40 アレイへ
最後までフルaryeh数は313 ....

である私はこれを好きにしようとした:

$tim = date('i'); 
$first = $tim + 9; 
$end = $first * 2; 
//This array is small: 
$woides = '["2254365","2255017","2254288","2220745","2254452","2255239","2232426","2255143","2248513","2254295","2233629","2238651","2254901","2238430","2239471","2255294","2217888","2242302","2242310","2220380","56121236","2255244","2235716","2246897","2246737","2254887","2247978","2239897","2241012","2254335","2220237","2255028","2235095","2227798","2239447","2254980","2255007","2220163","2254340","2254572","2239514","2255272","2254465","2235742","2254835","2255162","2248951","2255162","2226917","2227166","2226813","2232705","2228886","2253837","2239974","2241068","2254978","2241496","2254777","2254277","2254714","2223700","2254538","2254929","2254463","2254730","2220651","2223937","2210917","2218965","2254774","2254616","2253001","2227270","2248955","2245845","2246022","2225224","2251945","56120984","2226503","2254339","2254457","2255184"]'; 
$input = json_decode($woides); 
$output = array_slice($input, $first, $end); 
echo '<pre>'; 
print_r($output); 

これはどのようにして改善できますか?

+1

、それは彼らの審査を依頼する方が理にかなっています – amrdruid

+0

Ok、very nice.tnx –

答えて

0

$firstの計算を変更します。またarray_sliceは3番目の引数として最後の項目の配列ではなく、インデックスの長さを取る:あなたはhttp://codereview.stackexchange.com/にコードレビューを依頼することができます

$tim = date('i'); 
$first = $tim - ($tim % 10) + 1; 
$arrayLength = 10; 
//This array is small: 
$woides = '["2254365","2255017","2254288","2220745","2254452","2255239","2232426","2255143","2248513","2254295","2233629","2238651","2254901","2238430","2239471","2255294","2217888","2242302","2242310","2220380","56121236","2255244","2235716","2246897","2246737","2254887","2247978","2239897","2241012","2254335","2220237","2255028","2235095","2227798","2239447","2254980","2255007","2220163","2254340","2254572","2239514","2255272","2254465","2235742","2254835","2255162","2248951","2255162","2226917","2227166","2226813","2232705","2228886","2253837","2239974","2241068","2254978","2241496","2254777","2254277","2254714","2223700","2254538","2254929","2254463","2254730","2220651","2223937","2210917","2218965","2254774","2254616","2253001","2227270","2248955","2245845","2246022","2225224","2251945","56120984","2226503","2254339","2254457","2255184"]'; 
$input = json_decode($woides); 
$output = array_slice($input, $first, $arrayLength); 
echo '<pre>'; 
print_r($output); 
+0

あなたのコードは正しく機能しません。私は10分ごとに1回前(毎分)にしたい。 tnx –

関連する問題