Home > Backend Development > PHP Tutorial > is_array判断不起作用

is_array判断不起作用

WBOY
Release: 2016-06-23 14:02:04
Original
980 people have browsed it

我只是想去除sizes字段的重复,写入数组,然后输出,
但写入数组时用IS_ARRAY判断好像没起作用,结果还是都写进去了
或者还有没有其他更好的方法来去除这个字段的重复
这是表


$sizes = mysql_query("SELECT sizes FROM product");

$_sizearry = array();
while (!!$_sizes = mysql_fetch_array($sizes)){
               if (!is_array($_sizes['sizes'],$_sizearry)) {
   $_sizearry[] = $_sizes['sizes'];
}
}
print_r($_sizearry);
foreach($_sizearry as $size){
echo $size;}?>


回复讨论(解决方案)

print_r($_sizearry);这句是测试,没用

而且输出时委朋问题

is_array()不是用来判断是否有重复数据的
select distinct

怎么是 is_array 呢?检查是否是数组?
if (! in_array($_sizes['sizes'],$_sizearry)) {

is_array()是否是数组类型
in_array()判断数组是否有这个键值。

while (!!$_sizes = mysql_fetch_array($sizes)){               if (!in_array($_sizes['sizes'],$_sizearry)) {                    $_sizearry[] = $_sizes['sizes'];
Copy after login

其实是GROUP BY 就行了

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template