热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

PHP中文函数连载(二)-PHP源码

ec(2);函数count()描述:计算一变量中元素的个数intcount(mixedvar);Returnsthenumberofelementsinvar,whichistypicallyanarray(sinceanythingelsewillhaveoneelement).Returns0ifthevariable

函数count()
描述:
计算一变量中元素的个数
int count (mixed var);
Returns the number of elements in var , which is typically an array (since anything else will have one element).
Returns 0 if the variable is not set.
Returns 1 if the variable is not an array.

函数current()
描述:
传回数组指针目前所指的元素

mixed current (array array);

Each array variable has an internal pointer that points to one of its elements. In addition, all of the elements in the array are linked by a bidirectional linked list for traversing purposes. The internal pointer points to the first element that was inserted to the array until you run one of the functions that modify that pointer on that array.

The current() function simply returns the array element that's currently being pointed by the internal pointer. It does not move the pointer in any way. If the internal pointer points beyond the end of the elements list, current() returns false.

函数each()
描述:
返回数组中下一对key/value的值

array each (array array);

Returns the current key/value pair from the array array and advances the array cursor. This pair is returned in a four-element array, with the keys 0 , 1 , key , and value . Elements 0 and key each contain the key name of the array element, and 1 and value contain the data.

Example 1. each() examples

$foo = array( "bob", "fred", "jussi", "jouni" ); $bar = each( $foo );
$bar now contains the following key/value pairs:

0 => 0
1 => 'bob'
key => 0
value => 'bob'

$foo = array( "Robert" => "Bob", "Seppo" => "Sepi" ); $bar = each( $foo );

$bar now contains the following key/value pairs:

0 => 'Robert'
1 => 'Bob'
key => 'Robert'
value => 'Bob'

Example 2. Traversing $HTTP_POST_VARS with each()

echo "Values submitted via POST method:
";
while ( list( $key, $val ) = each( $HTTP_POST_VARS ) ) {
echo "$key => $val
";
}

函数end()
描述:
将数组中的指针移到最后一个
end (array array);
end() advances array 's internal pointer to the last element.

函数key()
描述:
从一数组中取出key
mixed key (array array);
key() returns the index element of the current array position.

函数ksort()
描述:
以key来排列一数组
Example 1. ksort() example

$fruits = array("d"=>"lemon","a"=>"orange","b"=>"banana","c"=>"apple");
ksort($fruits);
for(reset($fruits);
$key = key($fruits);
next($fruits)) { echo "fruits[$key] = ".$fruits[$key]." "; }

This example would display: fruits[a] = orange fruits[b] = banana fruits[c] = apple fruits[d] = lemon

函数list()
描述:
用类似数组的方式去指定一整串变量的值
Example 1. list() example



while (list($id, $name, $salary) = mysql_fetch_row($result)) {
print(" "." "." "." ");
}
?>
Employee name Salary
$name$salary

函数next()
描述:
将数组的指向指到下一组数据


函数pos()
描述:
传回数组的当前的数据

函数prev()
描述:
传回数组的前一条的数据

函数reset()
描述:
数组的指针指到第一条

函数rsort ()
描述:
以倒序方式排列一个数组
Example 1. rsort() example

$fruits = array("lemon","orange","banana","apple");
rsort($fruits);
for(reset($fruits); ($key,$value) = each($fruits); ) {
echo "fruits[$key] = ".$value." ";
}

This example would display: fruits[0] = orange fruits[1] = lemon fruits[2] = banana fruits[3] = apple The fruits have been sorted in reverse alphabetical order.

函数sizeof()
描述:
取得一个数组的大小和元素的数目

函数sort()
描述:
排序数组
Example 1. sort() example

$fruits = array("lemon","orange","banana","apple");
sort($fruits);
for(reset($fruits);
$key = key($fruits);
next($fruits)) {
echo "fruits[$key] = ".$fruits[$key]." ";
}

This example would display: fruits[0] = apple fruits[1] = banana fruits[2] = lemon fruits[3] = orange The fruits have been sorted in alphabetical order.

函数uasort()
描述:
以自定义的方式排列一个数组且序列不变。


函数uksort()
描述:
以自定义的方式以key排列
This function will sort the keys of an array using a user-supplied comparison function. If the array you wish to sort needs to be sorted by some non-trivial criteria, you should use this function. Example 1. uksort()

推荐阅读
  • 本文介绍了在开发Android新闻App时,搭建本地服务器的步骤。通过使用XAMPP软件,可以一键式搭建起开发环境,包括Apache、MySQL、PHP、PERL。在本地服务器上新建数据库和表,并设置相应的属性。最后,给出了创建new表的SQL语句。这个教程适合初学者参考。 ... [详细]
  • 搭建Windows Server 2012 R2 IIS8.5+PHP(FastCGI)+MySQL环境的详细步骤
    本文详细介绍了搭建Windows Server 2012 R2 IIS8.5+PHP(FastCGI)+MySQL环境的步骤,包括环境说明、相关软件下载的地址以及所需的插件下载地址。 ... [详细]
  • PHP设置MySQL字符集的方法及使用mysqli_set_charset函数
    本文介绍了PHP设置MySQL字符集的方法,详细介绍了使用mysqli_set_charset函数来规定与数据库服务器进行数据传送时要使用的字符集。通过示例代码演示了如何设置默认客户端字符集。 ... [详细]
  • 本文介绍了如何使用php限制数据库插入的条数并显示每次插入数据库之间的数据数目,以及避免重复提交的方法。同时还介绍了如何限制某一个数据库用户的并发连接数,以及设置数据库的连接数和连接超时时间的方法。最后提供了一些关于浏览器在线用户数和数据库连接数量比例的参考值。 ... [详细]
  • 本文介绍了Redis的基础数据结构string的应用场景,并以面试的形式进行问答讲解,帮助读者更好地理解和应用Redis。同时,描述了一位面试者的心理状态和面试官的行为。 ... [详细]
  • Metasploit攻击渗透实践
    本文介绍了Metasploit攻击渗透实践的内容和要求,包括主动攻击、针对浏览器和客户端的攻击,以及成功应用辅助模块的实践过程。其中涉及使用Hydra在不知道密码的情况下攻击metsploit2靶机获取密码,以及攻击浏览器中的tomcat服务的具体步骤。同时还讲解了爆破密码的方法和设置攻击目标主机的相关参数。 ... [详细]
  • 在说Hibernate映射前,我们先来了解下对象关系映射ORM。ORM的实现思想就是将关系数据库中表的数据映射成对象,以对象的形式展现。这样开发人员就可以把对数据库的操作转化为对 ... [详细]
  • 本文介绍了在SpringBoot中集成thymeleaf前端模版的配置步骤,包括在application.properties配置文件中添加thymeleaf的配置信息,引入thymeleaf的jar包,以及创建PageController并添加index方法。 ... [详细]
  • 本文由编程笔记小编整理,介绍了PHP中的MySQL函数库及其常用函数,包括mysql_connect、mysql_error、mysql_select_db、mysql_query、mysql_affected_row、mysql_close等。希望对读者有一定的参考价值。 ... [详细]
  • 本文介绍了在Mac上搭建php环境后无法使用localhost连接mysql的问题,并通过将localhost替换为127.0.0.1或本机IP解决了该问题。文章解释了localhost和127.0.0.1的区别,指出了使用socket方式连接导致连接失败的原因。此外,还提供了相关链接供读者深入了解。 ... [详细]
  • 解决VS写C#项目导入MySQL数据源报错“You have a usable connection already”问题的正确方法
    本文介绍了在VS写C#项目导入MySQL数据源时出现报错“You have a usable connection already”的问题,并给出了正确的解决方法。详细描述了问题的出现情况和报错信息,并提供了解决该问题的步骤和注意事项。 ... [详细]
  • 本文介绍了在Hibernate配置lazy=false时无法加载数据的问题,通过采用OpenSessionInView模式和修改数据库服务器版本解决了该问题。详细描述了问题的出现和解决过程,包括运行环境和数据库的配置信息。 ... [详细]
  • Oracle Database 10g许可授予信息及高级功能详解
    本文介绍了Oracle Database 10g许可授予信息及其中的高级功能,包括数据库优化数据包、SQL访问指导、SQL优化指导、SQL优化集和重组对象。同时提供了详细说明,指导用户在Oracle Database 10g中如何使用这些功能。 ... [详细]
  • 原文地址:https:www.cnblogs.combaoyipSpringBoot_YML.html1.在springboot中,有两种配置文件,一种 ... [详细]
  • yum安装_Redis —yum安装全过程
    篇首语:本文由编程笔记#小编为大家整理,主要介绍了Redis—yum安装全过程相关的知识,希望对你有一定的参考价值。访问https://redi ... [详细]
author-avatar
终结者
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有