PHP Programing language

array_combine() Function in PHP
Previous Home Next
adplus-dvertising

array_combine()

The array_combine() function creates an array by using the elements from one "keys" array and one "values" array.

Syntax:
array_combine(keys,values);

In above syntax, "keys" are array of keys and "values" are array of values.

Example:

<?php
$fruit_name=array("Apple","Banana","Mango");
$fruit_weight=array("5kg","3kg","10kg");
$Total=array_combine($fruit_name,$fruit_weight);
print_r($Total);
?>

Output:

Array ( [Apple] => 5kg [Banana] => 3kg [Mango] => 10kg )

Previous Home Next