1、in_array():檢查數組中是否存在某個值
bool in_array ( mixed needle, array haystack [, bool strict])
檢查needle是否在數組haystack中,
如果第三個參數 strict 的值爲 TRUE 則 in_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;
}
}