Skip to main content

PHP Functions - array_merge() and array_combine()

PHP has lots of built-in functions. So that you may not remember all the the functions. Among those functions, array_merge and array_combine are 2 very useful php functions that are very useful for core php programmer.

array_merge() function:

array_merge() is a built-in php function that is used to merge two or more arrays in one place. Unlike array_combine, it does not need equal number of elements in the each array. Here is a simple example of array_merge();

Example
<?php
$data1 = array("id"=>"21","name"=>"RKA","contact"=>"9843XXXXXX");
$data2 = array("address"=>"Kathmandu, Nepal");
$arrayMerge = array_merge($data1,$data2);
print_r($arrayMerge);

?>

Output
Array ( [id] => 21 [name] => RKA [contact] => 9843XXXXXX [address] => Kathmandu, Nepal )


array_combine() function: 


array_combine() is also a built-in php function which is used for combine only 2 arrays. And both the array of parameters must have equal number of elements. In fact, array_combine function combines 2 array together and generates index array.

Example: 
<?php
$data3 = array("1","3","5","7");
$data4 = array("a","c","e","g");
$arrayCombine1 = array_combine($data3,$data4);
print_r($arrayCombine1);
?>

Output:
Array ( [1] => a [3] => c [5] => e [7] => g )

Comments

Popular posts from this blog

How to Put Meta Keywords in Each Blogger Post

Meta tags or keywords are very significant SEO terms. To find your site’s rank better in search engine, you have to add meta tags or keywords in every page of the website. But when you want to put keywords in every blogger posts, you can’t because there is only meta description place in blogger. There you cannot find keywords adding space. So if you want to add meta tags or keywords also, you have to add some codes on your template. Meta tags are also as important as meta description. Meta tags help you to increase healthy and better traffic.

Process of adding meta tags in each blogger post:-Suggestion:We always recommend you not to change any code of your template with keeping back up of your template.

Step 1. Log in into your blogger.
Step 2. Choose your one blog.
Step 3. Go to template>>edit html.
Step 4. And find the code <b:include data=’blog’ name=’all-head-content’/>
Step 5. Then paste the below codes below the above code.
<b:if cond='data:blog.url == "PAGE-UR…

How to add Latest Facebook Comment Box in Blogger

Facebook has provided many plugins for websites and blogs. Recently the developers of Facebook have released the plugins “Facebook Comment Box”. This is awesome plugin of the Facebook. Using this Facebook comment box your blogger and websites user or viewers can comment on your posts and those comments will be automatically shared in their Facebook Comment Wall.

Facebook comment box makes your visitors catch you easily, so this can be very important for those people who want directly interact with the admin and other visitors. I know there are various people who want to know the Facebook comment box on their blogger blog, Wordpress blog and many other site. So this tutorial can be the best solution for them. So now we will suggest you how to add simple comment box of Facebook in the blogger blog. You should that everything have its merits and demerits. Likewise, this Facebook comment box also its some advantages and some disadvantages.

First of all, here we are discuss about the adva…

Responsive Video in Site and Blog

Responsive in every web materials is the trend of current web world. I mean , in the context of web development, responsive site can be called fashion but it also has many advantages. Mobile friendly, user friendly, device friendly and browser friendly are its some advantages. But in order to make a perfect responsive site, your site should have all elements responsive like videos, photos etc. Hence embedding video also should be device friendly, then your site can be called fully responsive.

Now here I am just telling you to make an embedded video responsive. Lets see how we can make any embedded video responsive or device friendly. There is no much difficult to do this. You just follow the following steps. 
How to Make Responsive Youtube Embed Video?Step 01: In the beginning, you embed any video whose code can be like  <iframe width="560" height="315" src="https://www.youtube.com/embed/o2Tw-8rF8dI" frameborder="0" allowfullscreen></i…