php之基本语法

1、数组

具体参考:http://www.runoob.com/php/php-arrays.html
http://www.runoob.com/php/php-ref-array.html
数组之关联数组
创建

//方法1
$age=array("Peter"=>"35","Ben"=>"37","Joe"=>"43");

//方法2
$age['Peter']="35";
$age['Ben']="37";
$age['Joe']="43";

使用指定建

<?php
$age=array("Peter"=>"35","Ben"=>"37","Joe"=>"43");
echo "Peter is " . $age['Peter'] . " years old.";
?>

遍历

<?php
$age=array("Peter"=>"35","Ben"=>"37","Joe"=>"43");

foreach($age as $x=>$x_value)
{
echo "Key=" . $x . ", Value=" . $x_value;
echo "<br>";
}
?>

数组之数值数组

<?php
//定义数值数组
$cars=array("Volvo","BMW","Toyota");
$arrlength=count($cars); //返回数组长度
//遍历数值数组
for($x=0;$x<$arrlength;$x++)
{
echo $cars[$x];
echo "<br>";
}
?>

PHP array_column() 函数
具体参考http://www.runoob.com/php/func-array-column.html
array_column() 返回输入数组中某个单一列的值。

array_column(array,column_key,index_key);

array 必需。指定要使用的多维数组(记录集)。
column_key 必需。需要返回值的列。
index_key 可选。作为返回数组的索引/键的列

PHP array_merge()函数
具体参考http://www.w3school.com.cn/php/func_array_merge.asp
array_merge() 函数用于把一个或多个数组合并为一个数组

PHP array_push() 函数
array_push() 函数向数组尾部插入一个或多个元素

<?php
$a=array("red","green");
array_push($a,"blue","yellow"); //向数组尾部插入 "blue" 和 "yellow"
print_r($a);
?>

2、字符串

PHP strlen() 函数
具体参考http://www.runoob.com/php/func-string-strlen.html

<?php
echo strlen("Hello"); //函数返回字符串 "Hello" 的长度
?>

PHP trim() 函数
具体参考:http://www.runoob.com/php/func-string-trim.html
trim() 函数移除字符串两侧的空白字符或其他预定义字符,返回已修改的字符串

$name= 'dream';
trim($name)

3、函数怎么接收参数,怎么接收返回值

   public function index(){     
        $params = array();   //定义数组            
        $result = $this->queryList($params);//数组是形式参数
    }
   public function queryList($params=array()){
        //其他操作 
        return array('list'=>$list, 'page'=>$page->show());
    }

isset()方法和empty()方法

   $smx='smx';
   if( isset( $smx ) {
       //
   } 

save方法的返回值是影响的记录数,如果返回false则表示更新出错,因此一定要用恒等来判断是否更新失败。

给表格增加序号

posted on 2017-04-07 13:41  dreamstar  阅读(51)  评论(0编辑  收藏  举报