Tools, FAQ, Tutorials:
Copying Array Values to a List of Variables in PHP
How To Copy Array Values to a List of Variables in PHP?
✍: FYIcenter.com
If you want copy all values of an array to a list of variable, you can use the list() construct on the left side of an assignment operator. list() will only take values with integer keys starting from 0. Here is a PHP script on how to use list() construct:
<?php $array = array("Google", "Yahoo", "Netscape"); list($first, $second, $third) = $array; print("Test 1: The third site = $third\n"); list($month, $date, $year) = split("/","1/1/2006"); print("Test 2: Year = $year\n"); $array = array("Zero"=>"PHP", 1=>"Basic", "One"=>"Perl", 0=>"Pascal", 2=>"FORTRAN", "Two"=>"Java"); list($first, $second, $third) = $array; print("Test 3: The third language = $third\n"); ?>
This script will print:
Test 1: The third site = Netscape Test 2: Year = 2006 Test 3: The third language = FORTRAN
Test 2 uses the array returned by the split() function. Test 3 shows that list() will ignore any values with string keys.
⇒ PHP Built-in Functions for Arrays
⇐ Order of Array Values in PHP
2017-01-29, 3400🔥, 0💬
Popular Posts:
How to view API details on the Publisher Dashboard of an Azure API Management Service? You can follo...
How to extend json.JSONEncoder class? I want to encode other Python data types to JSON. If you encod...
How to use "{{...}}" Liquid Codes in "set-body" Policy Statement? The "{{...}}" Liquid Codes in "set...
What is the Azure AD v1.0 OpenID Metadata Document? Azure AD v1.0 OpenID Metadata Document is an onl...
What's Wrong with "while ($c=fgetc($f)) {}" in PHP? If you are using "while ($c=fgetc($f)) {}" to lo...