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, 6748👍, 0💬
Popular Posts:
How To Wirte a Simple JUnit Test Class? This is a common test in a job interview. You should be able...
What are the core functionalities in XML .NET framework? Can you explain in detail those functionali...
How To Enter Numeric Values as HEX Numbers? - MySQL FAQs - Introduction to SQL Basics If you want to...
How To Manage Transaction Isolation Level? - Oracle DBA FAQ - Introduction to PL/SQL Transaction iso...
If XML does not have closing tag will it work? No, every tag in XML which is opened should have a cl...