Conversion of PHP variables to arrays (extract and compact) _php Tutorial

Source: Internet
Author: User
In PHP, we can use the Extract or compact function to convert an array to a variable, so let's use these two functions to share two instances.

Compact multiple variable-to-array

The code is as follows Copy Code

Multiple variable to array
$name = ' Phpff ';
$email = ' phpff@phpff.com ';
$info =compact (' name ', ' email ');//Pass variable name
Print_r ($info);
/*
Array
(
[Name] = Phpff
[Email] = phpff@phpff.com
)
*/
?>

Extract array to multiple variables

The code is as follows Copy Code

Array to multiple variables
$capitalcities [' England '] = ' London ';
$capitalcities [' Scotland '] = ' Edinburgh ';
$capitalcities [' Wales '] = ' Cardiff ';
Extract ($capitalcities);//Convert to three variables England,scotland,wales
Print $Wales;//cardiff

?>

Cases

The code is as follows Copy Code

$my _array = Array ("A" = "Cat", "b" = "Dog", "c" = "Horse");
Extract ($my _array);
echo "$a = $a; $b = $b; $c = $c ";
?>

Results

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

http://www.bkjia.com/PHPjc/632672.html www.bkjia.com true http://www.bkjia.com/PHPjc/632672.html techarticle in PHP, we can use the Extract or compact function to convert an array to a variable, so let's use these two functions to share two instances. Compact multiple variable -to-array ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.