• Categories
    • PHP
    • phpMyAdmin
    • PHPMailer
    • FFMpeg
    • PHPEXcel
    • PHPDoc
    • PHPUnit
    • CakePHP
    • CakePHP 2.0
    • Cake PHP 2.1
    • CakePHP Model
    • Facebook PHP SDK
    • composer-php
    • PHP 7
    • PHP GD
    All Categories
  • About

Why does array_map() with null as callback create an "array of arrays"?

phparraysspecificationsarray-map


PHP Snippet 1:

$d = array_map('array', $a, $b, $c);

PHP Snippet 2:

$array = [
    [1 => 'one', 2 => 'two', 3 => 'three']
];
var_export(array_map(fn() => func_get_args(), ...$array));
echo "\n---\n";
var_export(array_map(null, ...$array));

PHP Snippet 3:

array (
  1 => 
  array (
    0 => 'one',
  ),
  2 => 
  array (
    0 => 'two',
  ),
  3 => 
  array (
    0 => 'three',
  ),
)
---
array (
  1 => 'one',
  2 => 'two',
  3 => 'three',
)

Related Snippets

Laravel Jetsream Profile page not loading on fresh install

Do I need to install `fxp/composer-asset-plugin` if I'm not doing front-end development

Laravel phpunit test failing authorization

Inserting Country Selection into MySQL PHP [duplicate]

Loading data from MySQL and populating dropdown select with jQuery Mobile, PHP

WAMP Virtual Host not working

how to insert data into select2 search input after scan using qrcode

I want to store data in new index as per my key in php [duplicate]

Uploading video to Youtube using Youtube Data API V3 and Google API Client PHP -- getting 401 (unauthorized) message

Combine array with same value and add other [duplicate]

Trying to iterate over a mongodb cursor twice - failing

mysql slow on updates for a well optimized query

Webscraping Symfony/Panther: Can't get HTML

Select option from dropdown menu with PHP and mySql

Nginx disallowing execution of PHP in uploads directory with Magento

About Contact Privacy policy Terms and conditions