How to create array of arrays using array_map() in php?

 


We can create array of arrays using array_map() function in PHP. To do this we have to pass null as parameter in place of functionName parameter and the list of arrays to create an array of arrays.

<?php 
$a = array(1, 2, 3); 
$b = array("e", "f", "g"); 
  
$result = array_map(null, $a, $b); 
  
print_r($result); 
?> 

Output:

Array
(
    [0] => Array
        (
            [0] => 1
            [1] => e
        )

    [1] => Array
        (
            [0] => 2
            [1] => f
        )

    [2] => Array
        (
            [0] => 3
            [1] => g
        )

)

 


Related #tags:     #php     #array     #multidimensional-array    

Related questions




Looking for change? Click below to prepare for technical interview.


Technical Interview Questions