PHP array_combine() Function : Two PHP arrays One as key and another as value

1664

PHP array_combine() Function

PHP array_combine  Function 

array_combine :

(PHP 5, PHP 7)
Creates an array by using one array for keys and another for its values

Parameters:

array $keys Array of keys to be used. Illegal values for key will be converted to string.
array $values Array of values to be used

Returns:

Type: array
Description: the combined array, FALSE if the number of elements for each array isn’t equal

Examples

Example 1: A simple array_combine() example


<?php
$a = array('delhi', 'Mumbai', 'lucknow');
$b = array('Sahil', 'Hozaifa', 'Kamil');
$c = array_combine($a, $b);

echo $c;
?>

The above example will output:


Array
(
[delhi] =Sahil
[Mumbai] =Hozaifa
[lucknow] =Kamil
)

See Also :

LEAVE A REPLY

Please enter your comment!
Please enter your name here