Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use extract and compact functions in PHP

Shulou Source: shulou.com Published: 2022-06-01 02:56:06 09月10日 Update

This article mainly introduces how to use extract and compact functions in PHP. It is very detailed and has a certain reference value. Friends who are interested must finish it!

Extract (import variables from an array into the current symbol table), compact (create an array containing variable names and their values)

A = "Original"; $my_array = array ("a" = > "Cat", "b" = > "Dog", "c" = > "Horse"); extract ($my_array); echo "\ $a = $a;\ $b = $b;\ $c = $c"

Output:

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

$firstname = "Peter"; $lastname = "Griffin"; $age = "41"; $result = compact ("firstname", "lastname", "age"); print_r ($result)

Output:

Array

(

[firstname] = > Peter

[lastname] = > Griffin

[age] = > 41

)

These are all the contents of the article "how to use extract and compact functions in PHP". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: Function content variable array article output lieutenant general value interest boy buddy more knowledge symbol industry information information channel channel reference help Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Shulou Information vpn Microsoft NVidia