php变量与数组的相互转换(extract)与(compact)
栏目:php教程时间:2014-05-05 05:02:11
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";
- ?>
-
-
------分隔线----------------------------
------分隔线----------------------------