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, 4952👍, 0💬
Popular Posts:
What is Native Image Generator (Ngen.exe)? The Native Image Generator utility (Ngen.exe) allows you ...
What is the difference between strings and character arrays? A major difference is: string will have...
What is CMM and different levels? explain? The Capability Maturity Model (CMM) is a process capabili...
How To Export Data to a CSV File? - Oracle DBA FAQ - Introduction to Oracle SQL Developer If you wan...
How To Merge Cells in a Row? - XHTML 1.0 Tutorials - Understanding Tables and Table Cells If you wan...