MY OWN EXPLANATION OF THE CONCEPTS OF ARRAY_MERGE() FUNCTION AND ARRAY_COMBINE() FUNCTION ALONG WITH ONE EXAMPLE "TAKE 4 ARRAYS THEN MERGE THE ARRAYS USING ARRAY_COMBINE() FUNCTION" USING BOOTSTRAP-5 CLASSES IN HTML AND PHP (COMMONLY USED IN CRUD OPERATION WHILE WORKING IN LIVE PROJECTS IN INDUSTRY AS A PHP WEB DEVELOPER)
MY OWN EXPLANATION OF THE CONCEPTS OF ARRAY_MERGE() FUNCTION AND ARRAY_COMBINE() FUNCTION ALONG WITH ONE EXAMPLE "TAKE 4 ARRAYS THEN MERGE THE ARRAYS USING ARRAY_COMBINE() FUNCTION" USING BOOTSTRAP-5 CLASSES IN HTML AND PHP (COMMONLY USED IN CRUD OPERATION WHILE WORKING IN LIVE PROJECTS IN INDUSTRY AS A PHP WEB DEVELOPER)
Hi Guys, Very good evening to all of you. So, today I am going to explain about the comcepts of array_merge() and array_combine() function using one example and also I am going to explain about the Bootstrap-5 classes which I have used in my example of array_merge() and array_combine() function.
So, without wasting any more time let's begin with the explanation.
Firstly, I am explaining about the concept of array_combine() function. So, array_combine() function is the function which can merge two arrays into one array. And array_combine() function should be of same size or same value. Like, I can't combine two arrays of different values or different size using array_combine() function but which is possible for array_merge() function. For example, like if one array is of 4 values and another array is of 5 values then I can't combine this two arrays using array_combine() function, yes but obviously I will be able to merge this two arrays using array_merge() function. And even array_combine() function returns associative array. Even, for array_combine() function, I can't combine more than two arrays. We can combine only maximum two arrays. Like as here in my example I have four arrays. So, as this 4 arrays I will not be able to combine using array_combine() function, so here firstly I have merge two arrays a1 and a3 into one array and then I have merge another two arrays a2 and a4 into one array.
Then coming to the explanantion of array_merge function. So, array_merge() function combines one array after another. array_merge() function returns index array or numerical array. In array_merge() function, I can merge more than two arrays, like it can be 3 or 4 or so on... . And in array_merge() function, array can be of different sizes or different values. It's not mandotory that if one array is of 4 values another array also needs to be of 4 values, it can be of 5 values also or 6 values or so on... .
Now coming to the concepts of bootstrap-5 classes which I have used in my example. So here firstly I have used bootstrap class="container mt-5" where container provides responsive, fixed-width layout with horizontal padding and mt-5 means it applies a small margin at the top. Then I have used the bootstrap class="mb-4 text-primary text-center" where mb-4 applies the margin at the bottom, where as text-primary applies the colour blue and text-center is applied to make the sentence at the middle i.e. in the center. Then I have used the bootstrap class="container p-5 bg-info border rounded shadow-sm text-danger fw-bold fs-3" where p-5 provides the padding value and bg-info provides the colour cyan and border rounded shadow-sm text-danger fw-bold fs-3 makes border with shadow as well as it makes the text more bolder and increases the size.
OUTPUT OF THE CODE:
Take 4 arrays then merge the arrays using array_combine() function.
Array ( [0] => Parnashri [1] => Sayanti [2] => Gargi [3] => Satindra [4] => Srestra [5] => Ankit [6] => Prantik [7] => Shounak )
Array ( [Puja] => Parnashri [Arunaditya] => Sayanti [Ayan] => Gargi [Abhishek] => Satindra [Anish] => Srestra [Debanjan] => Ankit [Partha] => Prantik [Debajyoti] => Shounak )
CODE:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<title>array_merge() function</title>
</head>
<body>
<div class="container mt-1">
<h1 class="mb-4 text-primary text-center">Take 4 arrays then merge the arrays using array_combine() function.</h1>
<div class="container p-5 bg-info border rounded shadow-sm text-danger fw-bold fs-3">
<?php
$a1=['Puja','Arunaditya','Ayan','Abhishek'];
$a2=['Parnashri','Sayanti','Gargi','Satindra'];
$a3=['Anish','Debanjan','Partha','Debajyoti'];
$a4=['Srestra','Ankit','Prantik','Shounak'];
$arrmer1=array_merge($a1,$a3);
$arrmer2=array_merge($a2,$a4);
print_r($arrmer1);
echo "<br>";
echo "<br>";
print_r($arrmer2);
echo "<br>";
echo "<br>";
$arrcom=array_combine($arrmer1,$arrmer2);
print_r($arrcom);
?>
</div>
</div>
</body>
</html>
.png)
Comments
Post a Comment