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 Join a List of Keys with a List of Values into an Array
How To Join a List of Keys with a List of Values into an Array? - PHP Script Tips - PHP Built-in Functions for Arrays
✍: FYIcenter.com
If you have a list keys and a list of values stored separately in two arrays, you can join them into a single array using the array_combine() function. It will make the values of the first array to be the keys of the resulting array, and the values of the second array to be the values of the resulting array. Here is a PHP script on how to use array_combine():
<?php $old = array(); $old["Zero"] = "PHP"; $old[1] = "Perl"; $old["Two"] = "Java"; $old["3"] = "C+"; $old[""] = "Basic"; $old[] = "Pascal"; $old[] = "FORTRAN"; $keys = array_keys($old); $values = array_values($old); print("Combined:\n"); $new = array_combine($keys, $values); print_r($new); print("\n"); print("Combined backward:\n"); $new = array_combine($values, $keys); print_r($new); print("\n"); ?>
This script will print:
Combined: Array ( [Zero] => PHP [1] => Perl [Two] => Java [3] => C+ [] => Basic [4] => Pascal [5] => FORTRAN ) Combined backward: Array ( [PHP] => Zero [Perl] => 1 [Java] => Two [C+] => 3 [Basic] => [Pascal] => 4 [FORTRAN] => 5 )
2007-04-21, 6692👍, 0💬
Popular Posts:
How to set a HTML document's background color? document.bgcolor property can be set to any appropria...
Can one change the mouse pointer in Forms? The SET_APPLICATION_PROPERTY build-in in Oracle Forms all...
How do we enable SQL Cache Dependency in ASP.NET 2.0? Below are the broader steps to enable a SQL Ca...
What is the FP per day in your current company?
How does one iterate through items and records in a specified block? One can use NEXT_FIELD to itera...