is_array判断不起作用,该如何解决

WBOY
Release: 2016-06-13 11:48:36
Original
1428 people have browsed it

is_array判断不起作用
我只是想去除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;}?>


------解决方案--------------------
is_array()不是用来判断是否有重复数据的
select distinct
------解决方案--------------------
怎么是 is_array 呢?检查是否是数组?
if (!in_array($_sizes['sizes'],$_sizearry)) {
------解决方案--------------------
is_array()是否是数组类型
in_array()判断数组是否有这个键值。

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

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!