• 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

Live search query using JS and PHP for QA forum

Laravel views are showing from cache on one server but works fine on other server

PHP if in_array() how to get the key as well?

Make certain characters of a word from string bold

Add restriction to WooCommerce coupons by allowed user ID

Laravel csrf token mismatch for ajax POST Request

Creating a config file in PHP

Laravel 5.1 Unknown database type enum requested

How do I truncate a decimal in PHP?

How to fix bootstrap multiselect search data using ajax

Laravel Sanctum CSRF not authenticating

Match single unknown parameter php (Morse-code Regex)

PHP code for generating decent-looking coupon codes (mix of letters and numbers)

How to get an Array value inside an object in an array Php [duplicate]

Laravel print last executed SQL query with Query log

About Contact Privacy policy Terms and conditions