1.PHP数组的创建用array()函数,PHP数组元素的动态添加用array_push()函数。
<?php
$a=array("Dog","Cat");
array_push($a,"Horse","Bird");
print_r($a);
?>
2.PHP字符串替换:
str_replace(find,replace,string,count)
参数 | 描述 |
---|---|
find | 必需。规定要查找的值。 |
replace | 必需。规定替换 find 中的值的值。 |
string | 必需。规定被搜索的字符串。 |
count | 可选。一个变量,对替换数进行计数。 |
程序例子
- <?php
- echo str_replace("world","Gonn","Hello world!");
- ?>
运行结果:
Hello Gonn!
就是说,用 Gonn 来替换掉 "Hello world!" 中的 world。
程序例子
在本例中,我们将演示带有数组和 count 变量的 str_replace() 函数:
- <?php
- $arr = array("blue","red","green","yellow");
- print_r(str_replace("red","pink",$arr,$i));
- echo "Replacements: $i";
- ?>
运行结果:
Array ( [0] => blue [1] => pink [2] => green [3] => yellow ) Replacements: 1
就是说,用 pink 替换掉数组中的 red。然后计算替换的次数。
程序例子
- <?php
- $find = array("Hello","world");
- $replace = array("B");
- $arr = array("Hello","world","!");
- print_r(str_replace($find,$replace,$arr));
- ?>
运行结果:
Array ( [0] => B [1] => [2] => ! )
3.Ajax数据库
function getCommentDetail (id)
{
alert(id);
$.ajax({
type:"POST",
url:"http://localhost/EShop/items/js/index/ajax_part.php",
data:{product_id :id}//这两个变量不能重名
/*success:function(strValue)
{
alert(strValue);
}*/
});
}
其中poroduct和id代表的变量不能重名,否则会有意想不到的错误。
更新中。。。。。