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