PHP array_combine() function

P
PHP array_column function
PHP array_count_values() function

PHP array_combine() function as the name is suggesting, combines two arrays. This function requires the two arrays to have the same number of elements. It picks keys from the first array and values from another.

What is the syntax of the array_combine function in PHP?

array_combine(keys, values)
ParameterDescription
keysAn array of keys – required
valuesAn array of values – required
array_combine function in PHP
<?php
$first_name = array("Jawad","Ahmad","Sumit");
$age = array("24","25","39");

$combined_array = array_combine($first_name, $age);
print_r($combined_array);
?>

In the above example, we will have an array as output that contains first_names and corresponding ages from the other array.

PHP array_column function
PHP array_count_values() function

Add comment

Tutor Network

Share this

Learn PHP from A to Z