How to use array Combine in PHP

In this article, I will explain how the array_Combine() function can be used in PHP.
  • 1755

array_Combine() function in PHP

  • The array_Combine() function is used to creates an array by combining two other arrays, one array for keys and another for its values.

  • In array_Combine() function, both parameters must have equal number of elements.

Syntax

array_Combine(array1,array2)

Parameter

  • array1 array1 is required parameter. array1 is determine the keys.
  • array2 array2 is required parameter. array2 is determine the vaues.

Example

The following example show to how the array_Combine() function can be used in PHP.

<h3 style="color: darkturquoise;">array_combine() function example in PHP</h3>

    <?php 

    $sub =array('Hindi', 'Computer', 'Science', 'math'); 

    $marks = array(85, 95, 99, 72); 

    $subject_marks=array_combine($sub, $marks); 

    print_r($subject_marks) 

    ?> 

 

Output

combine.jpg

You may also want to read these related articles here
 
Ask Your Question 
 
Got a programming related question? You may want to post your question here
 

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.