PHP array_combine() Function

PHP array_combine() Function is used to create an array by using one array for keys and another for its values. PHP array_combine() function is PHP built-in function.

Syntax :

array_combine ( array $keys , array $values );

Parameter,

$keys : Required. It is Array of keys.

$values: Required. It is Array of values.

Return : It returns new array by combining keys of array and values of array. It returns false if number of elements for keys of array and values of array is not equal.

If the number of elements in keys and values does not match then it throws E_WARNING.

Let's see below example to understand php array_combine() Function in details.

 

Example :

<?php
$webtutorial= array("html","css","ajax","php");
$definition = array("HyperText Markup Language","Cascading Style Sheets","Asynchronous JavaScript And XML","Hypertext Preprocessor");
$tutorials=array_combine($webtutorial,$definition);
echo "<br>Get new combined array by combining two arrays using array_combine() function<br>";
print_r($tutorials);

?>

Output :

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

93578