php变量与数组的相互转换(extract)与(compact)
来源:程序员人生 发布时间:2014-05-05 05:02:11 阅读次数:2545次
compact 多个变量转数组,代码如下:
- <?php
-
- $name='phpff';
- $email='phpff@phpff.com';
- $info=compact('name','email');
- print_r($info);
-
-
-
-
-
-
-
- ?>
extract 数组转多个变量,代码如下:
- <?php
-
- $capitalcities['England'] = 'London';
- $capitalcities['Scotland'] = 'Edinburgh';
- $capitalcities['Wales'] = 'Cardiff';
- extract($capitalcities);
- print $Wales;
- ?>
实例代码如下:
- <?php
- $my_array = array("a" => "Cat","b" => "Dog", "c" => "Horse");
- extract($my_array);
- echo "$a = $a; $b = $b; $c = $c";
- ?>
-
-
生活不易,码农辛苦
如果您觉得本网站对您的学习有所帮助,可以手机扫描二维码进行捐赠