PHP array_combine() function
In this chapter you will learn:
- Description for PHP array_combine() function
- Node for PHP array_combine() function
- Syntax for PHP array_combine() function
- Parameter for array_combine() function
- Return for PHP array_combine() function
- Example for PHP array_combine() function
Description
The array_combine() function creates an associative array by using the elements from "keys" array and "values" array.
Note
Both arrays must have equal number of elements!
Syntax
array_combine has the following syntax.
array_combine(keys,values);
Parameter
Parameter | Is Required | Description |
---|---|---|
keys | Required. | Array of keys |
values | Required. | Array of values |
Return
array_combine() function returns the combined array. It returns FALSE if number of elements does not match.
Example
Create an array by using the elements from one "keys" array and one "values" array:
<?php/*ja v a 2 s. c om*/
$fname=array("Python","Java","HTML","java2s.com");
$age=array("5","7","3","9");
$c=array_combine($fname,$age);
print_r($c);
?>
The code above generates the following result.
Next chapter...
What you will learn in the next chapter:
- Definition for PHP array_count_values() function
- Syntax for PHP array_count_values() function
- Parameter for PHP array_count_values() function
- Return value from PHP array_count_values() function
- Example - Count all the values of an array
- Example - Count an associative array
Home » PHP Tutorial » PHP Array Functions