Saturday, April 25, 2020

CodeIgniter PHP : Merge Array

There are condition when we have two array and want to combine them. In PHP, we can use function array_merge() to merge those to array.
Below is the example how to use the function.


<?php
    $a1=array("a"=>"red","b"=>"green");
    $a2=array("c"=>"blue","b"=>"yellow");
    print_r(array_merge($a1,$a2));
?>

Result :
Array ([a]=>red [b]=>yellow [c]=>blue)

As you can see there are two value for key=b. But the result is going to print the 2nd array array as the value.

No comments:

Post a Comment

IONIC PASS PARAMETER

 To pass parameter to next page, first we need to make sure that we have 2 pages which is page from and page to. In page from ts file, you h...