extract()函數語法:
int extract( array $var_array [, int $extract_type = EXTR_OVERWRITE [, string $prefix ]] )
功能: extract()函數提取關聯數組(對數字索引數組無效對key和value,產生以key為變數名、value為對應值的多組新變數。
複製程式碼 程式碼如下:
$size = "old size"; //注意最後size變數的值。
$a = array(
"color" => "red",
"size" => "XXL",
"price" => "53");
extract( $a);
echo "color = $color
";
echo "size = $size
";
echo "price = $price
";
?>
複製程式碼 程式碼如下:
$a = array(
"color" = = > "red",
"size" => "XXL",
"price" => "53");
extract($a,EXTR_PREFIX_ALL,"SC");
echo " color = $SC_color
";
echo "size = $SC_size
";
echo "price = $SC_price
";
extract($a,EXTR_REFS) ;
$color="green";
echo $a['color']; //看原始數組的值
?>
以上就介紹了extractdata PHP extract 將數組拆分成多個變數的函數,包括了extractdata方面的內容,希望對PHP教程有興趣的朋友有所幫助。