php變量與數組的相互轉換(extract)與(compact)
來源:程序員人生 發布時間:2014-05-05 05:02:11 閱讀次數:2675次
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";
- ?>
-
-
生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈