array_combine function in php
array_combine() function creates an array by using elements of two arrays. Items of first array are used as keys in new array and the items of second array are used as values in new array.
- This function is used to create a new associative array with the use of two existing array.
- The items of first array are used as keys in new array and the items of second array are used as values in new array.
- It as an inbuilt function of PHP.
array_combine function syntax:
- Array_1 is the array which items is used as keys.
- Array_2 is the array which items is used as values.
array_combine function example:
<?php $array_1=array("Ram","Raj","Tanya"); // name of employees $array_2=array("12221","12222","12223"); // employee id of employees $new_array=array_combine($array_1,$array_2); echo '<pre>'; print_r($new_array); ?>
Waiting for your comments