Blogger Information
Blog 40
fans 0
comment 0
visits 16117
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
变量作用域和优化web1项目
飞天001
Original
320 people have browsed it

1. 变量作用域

  1. 在函数体内的变量,叫局部变量,只在函数体内有效,在函数体外不能被访问.
  2. 全局变量,无法在函数体内直接被调用,可以用两种方式被间接调用:

    (1).使用global关键字,可以间接访问

    1. global $one,$two;

    (2)可以用超全局变量访问 $GLOBALS.

    1. $GLOBALS['one'];
    2. $GLOBALS['two'];

2.web1项目优化

(1). 项目路径常量化定义

  1. //根路径
  2. define('DAY',date('/md',time()));
  3. define('ROOT_PATH',$_SERVER['DOCUMENT_ROOT'] . DAY . '/web1');
  4. //数据路径
  5. define('DATA_PATH', ROOT_PATH . '/data');
  6. //模板路径
  7. define('TMPL_PATH',ROOT_PATH . '/template');
  8. //公共模板路径
  9. define('TMPL_PUBLIC_PATH',TMPL_PATH . '/public');
  10. //静态资源路径
  11. define('STATIC_PATH', ROOT_PATH . '/static');
  12. define('STATIC_CSS_PATH', STATIC_PATH . '/css');
  13. define('STATIC_JS_PATH', STATIC_PATH . '/js');
  14. define('STATIC_IMG_PATH', STATIC_PATH . '/images');
  1. //每个页面引入配置文件
  2. include __DIR__.DS.'config'.DS.'common.php';

(2). 数据动态化

  1. // 新闻列表
  2. <?php foreach($news as $k => $v):extract($v)?>
  3. <a href="<?=$url?>" target="_blank"><?=mb_substr($title,0,18)?>...</a>
  4. <?php endforeach ?>
  1. // 产品列表
  2. <?php foreach($items as $v):extract($v)?>
  3. <div class="item">
  4. <img src="<?=$img?>" alt="" />
  5. <a href="<?=$url?>"><?=mb_substr($title,0,15)?>...</a>
  6. </div>
  7. <?php endforeach?>
Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post