How To Combine or Merge Array in PHP

In This blog, We Will Merge Two Array With Index Or Keys. There Are Mostly Two Array Used In PHP 
1. Indexed Array 
2. Associative Array 
In Indexed Array : Array Elements Stored In Index Like Eg: 0,1,2,3
In Associative Array: Array Elements Stored in Key LIke Eg: 'index'=>value



<?php 

////////indexed Array
$array=array("mango","Apple","Grapes");
echo $array[0];   ////mango

/////////Associative Array
$array=array("subject"=>Math,"fruit"=>Apple);
////access Array with key 
echo $array['subject'];  ///Math



Above We See How Array Store Element
In Php, Array Can Combine With array_combine() and Merge With array_merge() 

 



<?php

/////merge array with index
$book=array("HTML","CSS","PHP");
$price=array(400,300,750);
$bookprice=array_merge($book,$price);
print_r($bookprice);


///////combine array with key and Value
$book=array("HTML","CSS","PHP");
$price=array(400,300,750);
$bookprice=array_combine($book,$price);
print_r($bookprice);




Above Code Will Show Index And Associative Array Or How To Merge And Combine An Array

Demo: Array Combine Array Merge

Code Playground: Online PHP Php play Teh Playground

Categories: web development php
Written By : GUDDU KUMAR
Trending Courses

CodeIgniter

Regular : 45 Days

Fastrack : 20 Days

Crash : 10 Days

Advance Digital Marketing Expert Course

Regular : 6 Months

Fastrack : 3 Months

Crash : 2 Months

React JS

Regular : 45 Days

Fastrack : 25 Days

Crash : 15 Days

Laravel

Regular : 45 Days

Fastrack : 20 Days

Crash : 10 Days

Front End Developer

Regular : 6 Months

Fastrack : 4 Months

Crash : 2 Months

Web Expert with Python

Regular : 12 Months

Fastrack : 6 Months

Crash : 3 Months

Related Blogs

Request For Demo