Concept Of array_combine() Function In PHP In My Own Explanation With An Example "Take 4 Arrays Then Margin The Arrays Using array_combine() Function"
Concept Of array_combine() Function In PHP In My Own Explanation With An Example "Take 4 Arrays Then Margin The Arrays Using array_combine() Function"
So, here today I am going to explain about the concept of array_combine() function with an example.
But before starting with an explanation of array_combine() function, I like to mention that here I need to perform array_merge() function before and then only I can perform array_combine() function. Why is't so?, that I will explain while I will be explaining about array_combine() function below.
So, without wasting time just let's begin with my explanation of array_combine() function.
array_combine() function - array_combine() function is the function which merge two arrays into a single array. array_combine() function is the function which should have the same number of elements and same size array. array_combine() functions cannot merge more than two arrays at a time, and each array should be of same size in case of array_combine() function. To merge more than two arrays, I need to use array_merge() function which can merge more than two arrays like it can be three/four/five and so on... and array_merge() function can also be of different size.
CODE OF array_combine() FUNCTION =>
<?php
$arr1=["Parnashri","Sayanti","Ayan"];
$arr2=["Anish","Debanjan","Gargi"];
$arr3=["Satindra","Abhishek","Srestra"];
$arr4=["Bhaskar","Suman","Debajyoti"];
$arrmer1=array_merge($arr1,$arr2);//It merge the first two arrays $arr1 and $arr2 using array_merge() function
print_r($arrmer1);
echo "<br>";
$arrmer2=array_merge($arr3, $arr4);//It merge the first two arrays $arr3 and $arr4 using array_merge() function
print_r($arrmer2);
echo "<br>";
$arrcom=array_combine($arrmer1, $arrmer2);//It merges or rather I can say it combines the two merged arrays $arrmer1 and $arrmer1 using array_combine() function
print_r($arrcom);
?>
OUTPUT OF THE CODE OF array_combine() FUNCTION =>
Array ( [0] => Satindra [1] => Abhishek [2] => Srestra [3] => Bhaskar [4] => Suman [5] => Debajyoti )
Array ( [Parnashri] => Satindra [Sayanti] => Abhishek [Ayan] => Srestra [Anish] => Bhaskar [Debanjan] => Suman [Gargi] => Debajyoti )
"Array ( [0] => Parnashri [1] => Sayanti [2] => Ayan [3] => Anish [4] => Debanjan [5] => Gargi )" = Output of $arrmer1.
"Array ( [0] => Satindra [1] => Abhishek [2] => Srestra [3] => Bhaskar [4] => Suman [5] => Debajyoti )" = Output of $arrmer2.
"Array ( [Parnashri] => Satindra [Sayanti] => Abhishek [Ayan] => Srestra [Anish] => Bhaskar [Debanjan] => Suman [Gargi] => Debajyoti )" = Output of $arrcom.
Comments
Post a Comment