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, 7086👍, 0💬
Popular Posts:
What is application domain? Explain. An application domain is the CLR equivalent of an operation sys...
What will be printed as the result of the operation below: main() { int a=0; if (a==0) printf("Cisco...
What Articles Have You Read about JUnit? There are a number of JUnit articles that you should read: ...
Which bit wise operator is suitable for turning on a particular bit in a number? The bitwise OR oper...
Can you please post OpenLink Endur related FAQ's,tutorials,document s.Thanks