array_reverse,array_reverse php

http://www.itjxue.com  2023-01-06 17:31  来源:未知  点击次数: 

Php 交换数组中的键和值?

可以使用PHP内置函数array_flip(),将数组键名与值对调。

array_flip() 函数将使数组的键名与其相应值调换,即键名变成了值,而值变成了键名。

但注意键值不能一样才能使用。

(100分)[php]写几个你熟悉的字符串处理函数!

推荐你查看官方PHP手册,以下是摘取相关的资料:

addcslashes — 以 C 语言风格使用反斜线转义字符串中的字符

addslashes — 使用反斜线引用字符串

bin2hex — 将二进制数据转换成十六进制表示

chop — rtrim 的别名

chr — 返回指定的字符

chunk_split — 将字符串分割成小块

convert_cyr_string — 将字符由一种 Cyrillic 字符转换成另一种

convert_uudecode — 解码一个 uuencode 编码的字符串

convert_uuencode — 使用 uuencode 编码一个字符串

count_chars — 返回字符串所用字符的信息

crc32 — 计算一个字符串的 crc32 多项式

crypt — 单向字符串散列

echo — 输出一个或多个字符串

explode — 使用一个字符串分割另一个字符串

fprintf — 将格式化后的字符串写入到流

get_html_translation_table — 返回使用 htmlspecialchars 和 htmlentities 后的转换表

hebrev — 将逻辑顺序希伯来文(logical-Hebrew)转换为视觉顺序希伯来文(visual-Hebrew)

hebrevc — 将逻辑顺序希伯来文(logical-Hebrew)转换为视觉顺序希伯来文(visual-Hebrew),并且转换换行符

hex2bin — Decodes a hexadecimally encoded binary string

html_entity_decode — Convert all HTML entities to their applicable characters

htmlentities — Convert all applicable characters to HTML entities

htmlspecialchars_decode — Convert special HTML entities back to characters

htmlspecialchars — Convert special characters to HTML entities

implode — Join array elements with a string

join — 别名 implode

lcfirst — Make a string's first character lowercase

levenshtein — Calculate Levenshtein distance between two strings

localeconv — Get numeric formatting information

ltrim — Strip whitespace (or other characters) from the beginning of a string

md5_file — 计算指定文件的 MD5 散列值

md5 — 计算字符串的 MD5 散列值

metaphone — Calculate the metaphone key of a string

money_format — Formats a number as a currency string

nl_langinfo — Query language and locale information

nl2br — 在字符串所有新行之前插入 HTML 换行标记

number_format — Format a number with grouped thousands

ord — 返回字符的 ASCII 码值

parse_str — 将字符串解析成多个变量

print — 输出字符串

printf — 输出格式化字符串

quoted_printable_decode — Convert a quoted-printable string to an 8 bit string

quoted_printable_encode — Convert a 8 bit string to a quoted-printable string

quotemeta — Quote meta characters

rtrim — 删除字符串末端的空白字符(或者其他字符)

setlocale — Set locale information

sha1_file — 计算文件的 sha1 散列值

sha1 — 计算字符串的 sha1 散列值

similar_text — 计算两个字符串的相似度

soundex — Calculate the soundex key of a string

sprintf — Return a formatted string

sscanf — Parses input from a string according to a format

str_getcsv — 解析 CSV 字符串为一个数组

str_ireplace — str_replace 的忽略大小写版本

str_pad — 使用另一个字符串填充字符串为指定长度

str_repeat — 重复一个字符串

str_replace — 子字符串替换

str_rot13 — 对字符串执行 ROT13 转换

str_shuffle — 随机打乱一个字符串

str_split — 将字符串转换为数组

str_word_count — 返回字符串中单词的使用情况

strcasecmp — 二进制安全比较字符串(不区分大小写)

strchr — 别名 strstr

strcmp — 二进制安全字符串比较

strcoll — 基于区域设置的字符串比较

strcspn — 获取不匹配遮罩的起始子字符串的长度

strip_tags — 从字符串中去除 HTML 和 PHP 标记

stripcslashes — 反引用一个使用 addcslashes 转义的字符串

stripos — 查找字符串首次出现的位置(不区分大小写)

stripslashes — 反引用一个引用字符串

stristr — strstr 函数的忽略大小写版本

strlen — 获取字符串长度

strnatcasecmp — 使用“自然顺序”算法比较字符串(不区分大小写)

strnatcmp — 使用自然排序算法比较字符串

strncasecmp — 二进制安全比较字符串开头的若干个字符(不区分大小写)

strncmp — 二进制安全比较字符串开头的若干个字符

strpbrk — 在字符串中查找一组字符的任何一个字符

strpos — 查找字符串首次出现的位置

strrchr — 查找指定字符在字符串中的最后一次出现

strrev — 反转字符串

strripos — 计算指定字符串在目标字符串中最后一次出现的位置(不区分大小写)

strrpos — 计算指定字符串在目标字符串中最后一次出现的位置

strspn — 计算字符串中全部字符都存在于指定字符集合中的第一段子串的长度。

strstr — 查找字符串的首次出现

strtok — 标记分割字符串

strtolower — 将字符串转化为小写

strtoupper — 将字符串转化为大写

strtr — 转换指定字符

substr_compare — 二进制安全比较字符串(从偏移位置比较指定长度)

substr_count — 计算字串出现的次数

substr_replace — 替换字符串的子串

substr — 返回字符串的子串

trim — 去除字符串首尾处的空白字符(或者其他字符)

ucfirst — 将字符串的首字母转换为大写

ucwords — 将字符串中每个单词的首字母转换为大写

vfprintf — 将格式化字符串写入流

vprintf — 输出格式化字符串

vsprintf — 返回格式化字符串

wordwrap — 打断字符串为指定数量的字串

====================

这其中我熟悉的有:

echo — 输出一个或多个字符串

explode — 使用一个字符串分割另一个字符串

addslashes — 使用反斜线引用字符串

bin2hex — 将二进制数据转换成十六进制表示

html_entity_decode — Convert all HTML entities to their applicable characters

htmlentities — Convert all applicable characters to HTML entities

htmlspecialchars_decode — Convert special HTML entities back to characters

htmlspecialchars — Convert special characters to HTML entities

implode — Join array elements with a string

..........

大部分都用过

php 怎么反向遍历一个数组

把他倒序一次

foreach(array_reverse($a) as $i=$v){

echo $v;

}

lookup大于今天的一个值

可以先把数组每个都乘以-1,再找,然后再乘以-1。

不过lookup应该有个参数直接设定是大于等于该数值的最小值。如果是PHP则用array_reverse,JS用Array的reverse方法。

LOOKUP函数是Excel中的一种运算函数,实质是返回向量或数组中的数值,要求数值必须按升序排序。

PHP如何让数据倒序显示?

PHP让数据倒序显示有两种方法,

1.如果直接是字符串或者是数组,分别用strrev 或者array_reverse()反转。

2.可以自己写一个算法,让字符串反转过来$str = "abcdef";for ($i=1; $i=strlen($str); $i++){?echo substr($str , -$i , 1);}。

PHP(外文名:PHP: Hypertext Preprocessor,中文名:“超文本预处理器”)是一种通用开源脚本语言。

语法吸收了C语言、Java和Perl的特点,利于学习,使用广泛,主要适用于Web开发领域。PHP 独特的语法混合了C、Java、Perl以及PHP自创的语法。

它可以比CGI或者Perl更快速地执行动态网页。用PHP做出的动态页面与其他的编程语言相比,PHP是将程序嵌入到HTML(标准通用标记语言下的一个应用)文档中去执行,执行效率比完全生成HTML标记的CGI要高许多。

PHP还可以执行编译后代码,编译可以达到加密和优化代码运行,使代码运行更快。

谁帮编写个把阿拉伯数字形式的价格转换成中文形式的程序

例子:102.34的中文写法是:壹百零贰圆叁角肆分

\**********************************************************/

function my_chinese_price($input)

{

//将价格分隔成整数部分和小数部分,并强制转换成字符串类型

$price = explode("." , $input);

$int = (string)$price[0];

$dec = (string)$price[1];

//变量初始化

$result = "";

$array_stack = array();

$array_result = array();

$chinese_number = array("零","壹","贰","叁","肆","伍","陆","柒","捌","玖");

$position_static = array(

array("","拾","百","千"),

array("","拾","百","千"),

array("","拾","百","千")

);

$position_dynamic = array("","万","亿");

$mmm = array("角","分");

//处理整数部分

for ($i = 0 ; $i strlen($int) ; $i++)

{

array_unshift($array_stack , $chinese_number[$int[$i]]);

}

$array_block = array_chunk($array_stack , 4);

for ($i = count($array_block) - 1 ; $i = 0 ; $i--)

{

foreach ($array_block[$i] as $key = $value)

{

if ($value != "零")

{

$position_static[$i][$key] .= $position_dynamic[$i];

break;

}

}

foreach (array_reverse($array_block[$i] , TRUE) as $key = $value)

{

if ($value != "零")

{

array_push($array_result , $value . $position_static[$i][$key]);

}

else

{

array_push($array_result , $value);

}

}

}

foreach ($array_result as $value)

{

$result .= $value;

}

$result = ereg_replace("(零){2,}" , "零" , $result);

$result = ereg_replace("(零)$" , "" , $result);

$result .= "圆";

//处理小数部分

for ($j = 0 ; $j strlen($dec) ; $j++)

{

if ($dec[$j] != "0")

{

$result .= $chinese_number[$dec[$j]] . $mmm[$j];

}

else

{

$result .= "零";

}

}

$result = ereg_replace("(零){1,2}$" , "" , $result);

$result = ereg_replace("^(圆)(零)?" , "" , $result);

return $result;

}

?

[/php]

input.php

[php]

?php

/********************************************************\

要考虑的情况很多,如下:

1234567890的中文写法是:壹拾贰亿叁千肆百伍拾陆万柒千捌百玖拾圆

100000的中文写法是:壹拾万圆

2.05的中文写法是:贰圆零伍分

2.50的中文写法是:贰圆伍角

0.08的中文写法是:捌分

0.50的中文写法是:伍角

\********************************************************/

include "my_chinese_price.php";

$result = my_chinese_price($_POST["input"]);

if (!empty($_POST["input"]))

{

print $_POST["input"] . "的中文写法是:" . $result;

}

print '';

print '';

print '';

print '';

print '';

print '

';

print ' ';

print ' ';

print '

';

print '注备:价格支持到千亿,小数点后最多两位,例如:102.35的中文写法是:壹百零贰圆叁角伍分';

print '';

print '';

?

[/php]

不好意思 我是转载的~~

(责任编辑:IT教学网)

更多

推荐计算机等级考试文章