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
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 = "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  => Perl [Two] => Java  => C+  => Basic  => Pascal  => FORTRAN ) Combined backward: Array ( [PHP] => Zero [Perl] => 1 [Java] => Two [C+] => 3 [Basic] => [Pascal] => 4 [FORTRAN] => 5 )
2007-04-21, 6426👍, 0💬
Which bit wise operator is suitable for checking whether a particular bit is on or off? The bitwise ...
What is thread? A thread is an independent path of execution in a system.
What are unadjusted function points and how is it calculated? Unadjusted function points = ILF + EIF...
. How can a servlet refresh automatically if some new data has entered the database? You can use a c...
Write out a function that prints out all the permutations of a string. For example, abc would give y...