Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
How To Copy Array Values to a List of Variables
How To Copy Array Values to a List of Variables? - PHP Script Tips - Understanding PHP Arrays and Their Basic Operations
✍: 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.
2007-04-20, 5331👍, 0💬
Popular Posts:
How do we enable SQL Cache Dependency in ASP.NET 2.0? Below are the broader steps to enable a SQL Ca...
What Information Is Needed to Connect SQL*Plus an Oracle Server? - Oracle DBA FAQ - Introduction to ...
How To Create an Add-to-Netvibes Button on Your Website? - RSS FAQs - Adding Your Feeds to RSS News ...
What is the sequence of UML diagrams in project? First let me say some fact about this question, you...
What is the output of printf("%d")? 1. When we write printf("%d",x); this means compiler will print ...