php函数

来源:互联网 发布:tf idf算法实现 编辑:程序博客网 时间:2024/06/03 02:54

1、in_array():检查数组中是否存在某个值

               bool in_array ( mixed needle, array haystack [, bool strict])

               检查needle是否在数组haystack中,

             

             如果第三个参数 strict 的值为 TRUEin_array() 函数还会检查needle 的类型是否和haystack 中的相同。

注: 如果 needle 是字符串,则比较是区分大小写的。


一维数组实例:

<?php
$os
= array ("Mac","NT", "Irix", "Linux");
if (
in_array("Irix",$os)) {
print
"Got Irix";
}
if (
in_array("mac",$os)) {
print
"Got mac";
}
?> 

二维数组实例:

<?php
$a
= array(array('p','h'), array('p','r'), 'o');

if (
in_array(array ('p','h'), $a)) {
echo
"'ph' was found\n";
}
if (
in_array(array ('f','i'), $a)) {
echo
"'fi' was found\n";
}
if (
in_array('o',$a)) {
echo
"'o' was found\n";
}


2、mysql_affected_rows() 取得前一次 MySQL 操作所影响的记录行数

          实例:

                    mysql_connect('localhost','root','123');
                    mysql_select_db('news');
                    mysql_query("set names utf8");

                     $res = mysql_query("select id,title,content,newdate,c_name from new join category on new.news_cate_id=category.news_cate_id");
                      if(mysql_affected_rows()>0){
                   $new = array();
                    while($row = mysql_fetch_assoc($res)){
                          $new[]=$row;
                             }

}