• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

php基础语法学习汇总

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

常量学习:

<?php
# function demo
function sum($x,$y){
    $z=$x+$y;
    return $z;
}

echo sum(1,2);

#define demo
echo \'<br/>\';
define(\'hello\',\'ee\');
echo hello;

# strlen function dmeo
echo \'<br/>\';
$str=\'xxxeesssss\';
echo \'xxxeesssss\\'s lenght is:\'.strlen($str);

# _FILE_:current file name,
# _LINE_:current line number,
# _FUNCTION_:current function name,
# _CLASS_   :current class name,
# _METHOD_  :current object method name.
echo \'<br/>__FILE__:\';
echo __FILE__;
echo \'<br/>\';
echo \'dirname(__FILE__):\';
echo dirname(__FILE__);
echo \'<br/>__LINE__:\';
echo __LINE__;
echo \'<br/>__CLASS__:\';
echo __CLASS__;
echo \'<br/>__FUNCTION__:\';
echo __FUNCTION__;
echo \'<br/>__METHOD__:\';
echo __METHOD__;


require(dirname(__FILE__).\'\Person.php\');

$persion=new Person();
//echo \'<br/>\';
//echo $persion::test();
echo \'<br/>\';
echo $persion->test();
echo \'<br/>\';
require(dirname(__FILE__).\'\testutil.php\');
echo sayHello();
echo \'<br/>\';
echo sayHello();

echo \'<br/>\';
$actors[0]=\'array 00\';
$actors[1]=\'array 01\';
$actors[2]=\'array 02\';
$actors[3]=\'array 03\';
foreach($actors as $values){
    echo \'<br/>\'.$values;    
    echo \'<br/>$values\';
    echo "<br/>$values";
    echo "<br/>".$values;
}




?>
<?php
/*
 * Created on 2015年9月21日
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
 class Person{
    function __construct(){
        echo \'<br/>__CLASS__:\';
        echo __CLASS__;
        echo \'<br/>__FUNCTION__:\';
        echo __FUNCTION__;
        echo \'<br/>__METHOD__:\';
        echo __METHOD__;
    }    
    
    public function test(){
        echo \'test\';
    }
}
 
?>

 

if elseif else 

<?php
/*
 * Created on 2015年9月21日
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
 $count=10;
 
 if($count<1){
     echo \'less than 1\';
 }else if($count>2){
     echo \'over than 2\';
 }else if($count>3){
     echo \'over than 3\';
 }else if($count>9){
     echo \'over than 9\';
 }else{
     echo \'less or equal 9\';
 }
 
 echo \'<br/>\';
 
 $strVal=\'29298isudsfkjkwewrwer\';
 if(strlen($strVal)>10){
     echo \'the lenght over 10\';
 }else{
     echo \'the length no over 10\';
 }
 
?>

for foreach while 

 echo \'for($i=0;$i<10;$i++){...}\';
 for($i=0;$i<10;$i++){
     echo \'<br/>\'.$i;
 }
 
 echo \'<br/>\';
 echo \'foreach($a as $ b){echo $b}\';
 
 $actors=array(\'1\',\'2\',\'3\',\'4\');
 foreach($actors as $val){
     echo \'<br/>\'.$val;
 }

 echo \'while(...){...}\';
 
 $x =1;
 while($x<5){
     echo \'<br/>\'.$x;
     $x++;
 }
 
 echo \'<br/>\';
 echo \'do{...} while(...)\';
 $y=10;
 
 do{
     $y--;
     echo "<br/>$y";
 }while($y>1);
 

swtich:

<?php
/*
 * Created on 2015年9月21日
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
 
 $val=10;
 
 switch($val){
     case 1:
         echo \'1\';
         break;
     case 10:
         echo \'10\';
         break;
     default:
         echo \'other\';
         break;
 }
?>

array

<?php
/*
 * Created on 2015年9月21日
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
$a =array();
$a=array("1","2",\'3\');
print_r("<br/>");
print_r($a);

$a =array("x","y","z",1);
print_r("<br/>");
print_r(array_keys($a,1,true));
print_r("<br/>");
print_r(array_keys($a,"f",true));
print_r("<br/>");
print_r(array_values($a));
print_r("<br/>");
var_dump(is_array($a));

$a=array(\'fg\'=>\'飞\',\'s\'=>\'d\');
print_r("<br/>");
var_dump(array_key_exists(0,$a));
print_r("<br/>");
var_dump(array_key_exists("s",$a));
print_r("<br/>");
var_dump(key_exists("s",$a));

print_r("<br/>");
$arr=array("f"=>"dd","ds"=>"sx","s"=>1);
if(in_array("dd",$arr)){
    echo "f exists";
}else{
    echo "not exists";
}
print_r("<br/>");
var_dump(in_array(1,$a,true));
print_r("<br/>");
var_dump(in_array("1",$a,true));

?>

mysql_conn

<?php
/*
 * Created on 2015年9月21日
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
 
 $conn=mysql_connect(\'localhost\',\'root\',\'root\');
 if(!$conn){
     die(\'Could not connect:\'.mysql_error());
 }else{
     echo \'Connect mysql success!\';
 }
 
 $isCreateDbSuc=mysql_query(\'create database my_db;\',$conn);
 if($isCreateDbSuc){
     echo \'Create my_db success!\';
 }else{
     echo \'Error creating database:\'.mysql_error();
 }
 
 mysql_close($conn);
?>

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP基础语法发布时间:2022-07-10
下一篇:
php基础语法发布时间:2022-07-10
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap