变量初始化你如何写

WBOY
Release: 2016-06-13 10:17:38
Original
703 people have browsed it

变量初始化你怎么写?
数量少的变量初始化信手拈来
如果数量较多的时候就有点难受了

$a,$b,$c,$d,$e.....

写成这样
$a=0;
$b=0;
$c=0;
$d=0;
$e=0;
....

不好看,不方便,不舒服...

那么你怎么初始化?别告诉我不初始化,关闭错误提示.


------解决方案--------------------
$a=$b=$c=...=0;
$d=$e=...=array();
这样好看点了不? 哈哈 没碰到太多需要初始化的变量了
------解决方案--------------------
如果没有规律那就只能人肉了。有规律还好写。如果从数组中可以用 extract/list;
 引用一段:

PHP code
$my_array = array("a" => "Cat","b" => "Dog", "c" => "Horse");extract($my_array);echo "\$a = $a; \$b = $b; \$c = $c";  //输出:$a = Cat; $b = Dog; $c = Horse<br><font color="#e78608">------解决方案--------------------</font><br>我不会设计这么多变量哈哈。有几个就老老实实写几行<br><font color="#e78608">------解决方案--------------------</font><br>php 允许不初始化变量,这表现出了 php 的灵活性、简便性<br>如果一定要初始化,倒不如<br>extract(array_flip(explode(',', 'a,b,c,d,e,f,g,h')));<br><br>$a=0;<br>$b=0;<br>$c=0;<br>$d=0;<br>$e=0;<br>.... 烦!!<br><br>$a=$b=$c=...=0;<br>$d=$e=...=array();也烦!!<br><br><font color="#e78608">------解决方案--------------------</font><br>等哪天,php 变成编译型语言了,就不烦这个了。那又烦什么呢....<br><font color="#e78608">------解决方案--------------------</font><br>不仅要隔行写,而且每行还要加满注释。<br>话说做报表为啥要初始化这么多变量?共享下你的设计呗。<br>我也做过一个自定义的报表功能,选表选字段选关联选条件添加统计添加过滤搜索,好像没有类似说初始化多个变量的需要啊。<br><font color="#e78608">------解决方案--------------------</font><br>本来人家php设计的时候,就是可以变量啥时候用啥时候定义,不知道。那位哥,把php修正成了一种类似强类型的不伦不类的东西。跟个杂种一样。太不容易了,php程序员苦逼啊<div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!