PHP Array实用函数参考
array_flip
交换数组中的键和值
$arr1 = array('a'=>1,'b'=>2,'c'=>3,'d'=>4);
$array = array_flip($arr1);
showArr($array);
/*
Array
(
[1] => a
[2] => b
[3] => c
[4] => d
)
*/
array_key_exists
检查给定的键名或索引是否存在于数组中(也可用于对象)
$arr1 = array('a'=>1,'b'=>2,'c'=>3,'d'=>4);
echo array_key_exists('b',$arr1); //1 (true)
array_keys
返回数组中所有的键名
$arr1 = array('a'=>1,'b'=>2,'c'=>3,'d'=>4,5);
$array = array_keys($arr1);
showArr($array);
/*
Array
(
[0] => a
[1] => b
[2] => c
[3] => d
[4] => 0
)
*/
相关文档:
PHP
是我用过的语言中,最令人恼火的但同时也是最有趣的语言。我之所以说“令人恼火”主要是因为函数命名极其不一致。尽管我每天都要用到这些函数,我还是要想
一下“究竟是 str_pos 还是 strpos?是 str_split 还是
strsplit?”。另一方面,有时候可以用一行简单的代码就能解决一个难题。
下面 ......
Floating point precision
It is typical that simple decimal fractions like 0.1
or
0.7
cannot be converted into their internal binary
counterparts without a small loss of precision. This can lead to
confusing
results: for example, floor((0.1+0.7)*10)
will usually
return 7
......
在默认情况下,php的项目需要建在Apache Group\Apache\htdocs目录下才可以正常访问。当我们需要自己建立一个不在Apache Group\Apache\htdocs目录下的工作区间时,就需要改变Apache的访问指定路径。安装好Apache 后,在Apache Group\Apache\conf 下有一个文件httpd.conf,它里面包含着 ......
文件php.ini放入windows下,将下面内容拷贝到记事本命名为php.ini放入c:/windows下,重启Apache server:
[PHP]
;;;;;;;;;;;
; WARNING ;
;;;;;;;;;;;
; This is the default settings file for new PHP installations.
; By default, PHP installs itself with a configuration suitable for
; development purposes ......
当下载文件需要与服务端交互时,就需要用脚本来实现,而不是单纯地链接到文件的地址
下载mp3文件的例子
<?php
$file_path = './data/upload/song/sample.mp3';
$file_name = 'sample.mp3';
$file_size = filesize($file_path);
header ( "Pragma: public" );
header ( "Cache-Control: must-reval ......