Php Array Elements Combine Function

What is array_combine Function?

Explanation

The "array_combine" function is used to create an array by using one array for keys and another for its values.

Syntax:


array_combine(keyarray,valarray)

In the above syntax "keyarray" specify the keys of an array and "valarray" the values of an array.

Example :


<?php
$a = array('1', '2', '3');
$b = array('one', 'two', 'three');
$c = array_combine($a, $b);
?>
Result :

Array ( [1] => one [2] => two [3] => three )

In the above example, the keys as elements in the array $a is combined with valuesas elements in the array $b, to display the array elements.

PHP Topics


Ask Questions

Ask Question