Coding Villa

Create Array using array_combine function in PHP

Author : Tahreem Anwar

Share with Friends
Views : 299
Ratings : 0
Bookmarks : 0
Farourities : 0

Description


In this simple article you will learn about Create Array using array_combine function in PHP.


Advertisements


 

 

 

array_combine function:

 

The array_combine function combines two arrays. It takes two parameters first array as index values and second array as values.

 

Code:

 

<?php

$name_staring_values=array("T","R","A","M");

$names=array("Tahreem","Rizwan","Anwar","Misbah");

print_r(array_combine($name_staring_values,$names));

?>

 

Output:

 

Array ( [T] => Tahreem [R] => Rizwan [A] => Anwar [M] => Misbah )

 

Explanation:

 

The above code takes the values in the array $name_staring_values (representing the keys/index values) and combines them with the values in $names (representing the strings).

 

On line 4 then we have passed both arrays to array_combine function of php. print_r is like echo or print that print something on screen like print_r print entire array on screen by their index.

 

 

 



Article Tags
Share with Friends

Comments




Leave a Reply

Name (required)  
Mail (will not be published) (required)   
 
Enter This Code
Captcha
 

Advertisements

Article Categories

.NET


Databases


Mobile Development


Operating Systems


Web Development


Coding Villa on Facebook