Home >Backend Development >PHP Tutorial >关于查询问题

关于查询问题

WBOY
WBOYOriginal
2016-06-23 14:00:58935browse

比方说
$array_a={1,1,1,2,2,2,3,3,3,4,4,4,5,5,5}
$array_b={a,a,a,a,a,b,b,b,b,c,c,c,s,s,s}
$array_c={b,b,c,d,d,s,a,s,d,s,a,d,a,d,d}

把上面想象成数据库里的内容   3个字段 和内容

我想用PHP数组函数 实现 数据库where的查询 比方是where $array_a=1 内容就是aaa和bbc
用PHP怎么写呢   由于环境用数据库限制太多 我也没办法才用这个方法


回复讨论(解决方案)

你这个描述不对吧,,如果等于2,时等于3时呢?

没想到什么好办法,只能根据a的值去查相应元素的各自位置,再用这些位置去b,c里去取值

为何不这样:
$abc = array(array(1,'a','b'),array(1,'a','b'),)
或者存成文件模拟数据库。然后自定义search函数

$array_a = explode(',', '1,1,1,2,2,2,3,3,3,4,4,4,5,5,5');$array_b = explode(',', 'a,a,a,a,a,b,b,b,b,c,c,c,s,s,s');$array_c = explode(',', 'b,b,c,d,d,s,a,s,d,s,a,d,a,d,d');$res_a = array_keys($array_a, 1);$res_b = array_intersect_key($array_b, array_flip($res_a));$res_c = array_intersect_key($array_c, array_flip($res_a));print_r($res_b);print_r($res_c);
Array
(
    [0] => a
    [1] => a
    [2] => a
)
Array
(
    [0] => b
    [1] => b
    [2] => c
)

$array_a = explode(',', '1,1,1,2,2,2,3,3,3,4,4,4,5,5,5');$array_b = explode(',', 'a,a,a,a,a,b,b,b,b,c,c,c,s,s,s');$array_c = explode(',', 'b,b,c,d,d,s,a,s,d,s,a,d,a,d,d');$res_a = array_keys($array_a, 1);$res_b = array_intersect_key($array_b, array_flip($res_a));$res_c = array_intersect_key($array_c, array_flip($res_a));print_r($res_b);print_r($res_c);
Array
(
    [0] => a
    [1] => a
    [2] => a
)
Array
(
    [0] => b
    [1] => b
    [2] => c
)
利用array_intersect_key来搜索不错  array_flip($res_a)这个感觉是多余的?

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn