欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php變量與數(shù)組相互轉(zhuǎn)換的方法(extract與compact)

 更新時間:2016年12月02日 11:34:20   作者:flyfox  
這篇文章主要介紹了php變量與數(shù)組相互轉(zhuǎn)換的方法,結(jié)合實例形式分析了extract與compact函數(shù)的相關(guān)功能與使用技巧,需要的朋友可以參考下

本文實例講述了php變量與數(shù)組相互轉(zhuǎn)換的方法。分享給大家供大家參考,具體如下:

在php中數(shù)組與變量相互轉(zhuǎn)換我們可使用到extract或compact函數(shù),這里就來給大家分析一下這兩個函數(shù)的用法。

compact 多個變量轉(zhuǎn)數(shù)組

<?php
  //多個變量轉(zhuǎn)數(shù)組
  $name='jb51';
  $email='jb51@jb51.net';
  $info=compact('name','email');//傳遞變量名
  print_r($info);
  /*
  Array
  (
    [name] => jb51
    [email] => jb51@jb51.net
  )
  */
?>

extract 數(shù)組轉(zhuǎn)多個變量

<?php
//數(shù)組轉(zhuǎn)多個變量
  $capitalcities['England'] = 'London';
  $capitalcities['Scotland'] = 'Edinburgh';
  $capitalcities['Wales'] = 'Cardiff';
  extract($capitalcities);//轉(zhuǎn)變成三個變量 England,Scotland,Wales
  print $Wales;//Cardiff
?>

例:

<?php
$my_array = array("a" => "Cat","b" => "Dog", "c" => "Horse");
extract($my_array);
echo "$a = $a; $b = $b; $c = $c";
?>

結(jié)果:

$a = Cat; $b = Dog; $c = Horse

更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《php常用函數(shù)與技巧總結(jié)》、《PHP數(shù)組(Array)操作技巧大全》、《php字符串(string)用法總結(jié)》、《PHP錯誤與異常處理方法總結(jié)》、《PHP基本語法入門教程》、《php面向?qū)ο蟪绦蛟O(shè)計入門教程》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總

希望本文所述對大家PHP程序設(shè)計有所幫助。

相關(guān)文章

最新評論