note 129842 added to function.array
| From: | gaflores@dcc.uchile.cl | Date: | Thu, 07 Nov 2024 19:20:50 +0000 |
| Subject: | note 129842 added to function.array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-221637@lists.php.net to get a copy of this message | ||
As the note below the article says, "array() is a language construct used to represent literal
arrays, and not a regular function".
You can verify this by running
<?php
var_dump(function_exists('array'));
// not a proper function; shows bool(false)
?>
As such, you cannot pass it directly as a callback
<?php
var_dump(array_map('array', ['a', 'b', 'c']));
// this won't run. As of 8.3.6, throws a PHP Warning (Uncaught TypeError)
?>
You can bypass this by making an anonymous wrapper
<?php
var_dump(array_map(function ($x) { return array($x); }, ['a', 'b',
'c']));
// shows the desired array
?>
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.5.137 (proxied: 200.89.69.151)
----
Manual Page -- https://php.net/manual/en/function.array.php
Edit -- https://main.php.net/note/edit/129842
Del: integrated -- https://main.php.net/note/delete/129842/integrated
Del: useless -- https://main.php.net/note/delete/129842/useless
Del: bad code -- https://main.php.net/note/delete/129842/bad+code
Del: spam -- https://main.php.net/note/delete/129842/spam
Del: non-english -- https://main.php.net/note/delete/129842/non-english
Del: in docs -- https://main.php.net/note/delete/129842/in+docs
Del: other reasons-- https://main.php.net/note/delete/129842
Reject -- https://main.php.net/note/reject/129842
Search -- https://main.php.net/manage/user-notes.php