一、單一條件查詢(==)
在陣列中資料中,通過查詢條件得出想要的陣列
<?php
$ar = array(
2 => array(
'catid' => 2,
'catdir' => 'notice',
),5 => array(
'catid' => 5,
'catdir' => 'subject',
),6=> array(
'catid' => 6,
'catdir' => 'news'
),);$catdir_so = "subject";
$r = array_filter($ar, function($t) use ($catdir_so) );
print_r($r);
?>
二、時間段查詢(查個時間段內的資料)
在陣列中資料中,通過查詢條件得出想要的陣列
查詢某個時間段範圍內的資料
<?php
$ar = array(
2 => array(
'catid' => '6',
'catdir' => '1522332388000',//2018-03-29 22:06:28
),6=> array(
'catid' => '5',
'catdir' => '1522329351000'//2018-03-29 21:15:51
),7=> array(
'catid' => '4',
'catdir' => '1522328237000'//2018-03-29 20:56:15
),9=> array(
'catid' => '3',
'catdir' => '1522327772000'//2018-03-29 20:49:32
),10=> array(
'catid' => '2',
'catdir' => '1522325351000'//2018-03-29 20:09:11
),5 => array(
'catid' => '1',
'catdir' => '1522323606000',//2018-03-29 19:40:06
),);$catdir_so1 = "1522325351000";//2018-03-29 20:09:11 2
$catdir_so2 = "1522329351000";//2018-03-29 21:15:51 5
$r = array_filter($ar, function($t) use ($catdir_so1,$catdir_so2) );
print_r($r);
//echo strtotime("2018-03-29 21:15:51");
?>
$r = array_filter($ar, function($t) use ($catdir_so1,$catdir_so2) );
三、時間段查詢再加乙個條件(相當案例一加上案例二)
<?php
$ar = array(
2 => array(
'catid' => '6',
'cat' => 'dd',
'catdir' => '1522332388000',//2018-03-29 22:06:28
),6=> array(
'catid' => '5',
'cat' => 'dd',
'catdir' => '1522329351000'//2018-03-29 21:15:51
),7=> array(
'catid' => '4',
'cat' => 'ddfgd',
'catdir' => '1522328237000'//2018-03-29 20:56:15
),9=> array(
'catid' => '3',
'cat' => 'dd',
'catdir' => '1522327772000'//2018-03-29 20:49:32
),10=> array(
'catid' => '2',
'cat' => 'dvvd',
'catdir' => '1522325351000'//2018-03-29 20:09:11
),5 => array(
'catid' => '1',
'cat' => 'ddfgd',
'catdir' => '1522323606000',//2018-03-29 19:40:06
),);$catdir_so1 = "1522325351000";//2018-03-29 20:09:11 2
$catdir_so2 = "1522329351000";//2018-03-29 21:15:51 5
$catdir_so3 = "dd";
$r = array_filter($ar, function($t) use ($catdir_so1,$catdir_so2,$catdir_so3) );
print_r($r);
//echo strtotime("2018-03-29 21:15:51");
?>
$r = array_filter($ar, function($t) use ($catdir_so1,$catdir_so2,$catdir_so3) );
$type_mold_arr=array('1','2');//1=直播
$rsoc = array_values(array_filter($rsoc2, function($t) use ($pid,$type_mold_arr) ));//0=只取一組陣列(也只取第一組)
$a=array(
'0' => array('id'=>1,'pid'=>0,'name'=>'水果'),
'1' => array('id'=>2,'pid'=>0,'name'=>'蔬菜'),
'2' => array('id'=>3,'pid'=>1,'name'=>'食品'),
'3' => array('id'=>4,'pid'=>2,'name'=>'運動'),
'4' => array('id'=>5,'pid'=>1,'name'=>'電腦'),
'5' => array('id'=>6,'pid'=>'香果','name'=>'香蕉'),
'6' => array('id'=>7,'pid'=>4,'name'=>'牛奶'),
'7' => array('id'=>8,'pid'=>5,'name'=>'西瓜'),
'8' => array('id'=>9,'pid'=>7,'name'=>'蘋果'),
); $arr=$result=array();
foreach ($a as $key => $value)
} }foreach ($arr as $key => $value)
}var_dump( $result);
引用: 陣列 在陣列中查詢元素
description 輸入10個整數到乙個長度為10的整型陣列中,然後輸入乙個整數,檢視該整數是否在剛才得到的陣列中,如果在,輸出 found 如果不在,輸出 not found input 11 個整數 output 如果第11個整數在前10個整數中,則輸出found 如果第11個整數不在前10...
在陣列中查詢數字
在整型有序陣列中查詢想要的數字,查到了返回下標 折半查詢 define crt secure no warnings include include intmain int num scanf d num int left 0 int right 10 while left right else i...
6 6 在陣列中查詢指定元素
本題要求實現乙個在陣列中查詢指定元素的簡單函式。函式介面定義 int search int list,int n,int x 其中list是使用者傳入的陣列 n 0 是list中元素的個數 x是待查詢的元素。如果找到 則函式search返回相應元素的最小下標 下標從0開始 否則返回 1。裁判測試程式...