Tutorials Point


  Learning PHP
  Advanced PHP
  PHP Function Reference
  PHP Useful Resources
  Selected Reading

Copyright © 2014 by tutorialspoint



  Home     References     Discussion Forums     About TP  

PHP Function array_combine()


previous

Advertisements

Syntax

array array_combine ( array $keys, array $values );

Definition and Usage

Creates an array by using the values from the keys array as keys and the values from the values array as the corresponding values.

Paramters

ParameterDescription
keysArray of keys to be used
valuesArray of values to be used

Return Values

Returns the combined array, FALSE if the number of elements for each array isn't equal or if the arrays are empty.

Example

Try out following example:

<?php
$a = array('green', 'red', 'yellow');
$b = array('avocado', 'apple', 'banana');
$c = array_combine($a, $b);

print_r($c);
?> 

This will produce following result:

Array([green] => avocado [red] => apple [yellow] => banana)

previous Printer Friendly

Advertisements


  

Advertisements