{"id":1090,"date":"2021-04-13T09:04:53","date_gmt":"2021-04-13T09:04:53","guid":{"rendered":"https:\/\/phptutorial.net\/?page_id=1090"},"modified":"2025-04-06T07:22:09","modified_gmt":"2025-04-06T07:22:09","slug":"php-array_map","status":"publish","type":"page","link":"https:\/\/www.phptutorial.net\/php-tutorial\/php-array_map\/","title":{"rendered":"PHP array_map"},"content":{"rendered":"\n<p><strong>Summary<\/strong>: in this tutorial, you will learn how to use the PHP <code>array_map()<\/code> function that creates a new array whose elements result from applying a callback to each element.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='introduction-to-the-php-array_map-function'>Introduction to the PHP array_map() function <a href=\"#introduction-to-the-php-array_map-function\" class=\"anchor\" id=\"introduction-to-the-php-array_map-function\" title=\"Anchor for Introduction to the PHP array_map() function\">#<\/a><\/h2>\n\n\n\n<p>Suppose that you have an <a href=\"https:\/\/phptutorial.net\/php-tutorial\/php-array\/\">array<\/a> that holds the lengths of squares:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-meta\">&lt;?php<\/span>\n\n$lengths = &#91;<span class=\"hljs-number\">10<\/span>, <span class=\"hljs-number\">20<\/span>, <span class=\"hljs-number\">30<\/span>];<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>To calculate the areas of the squares, you may come up with the <code><a href=\"https:\/\/phptutorial.net\/php-tutorial\/php-foreach\/\">foreach<\/a><\/code> loop like this:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-meta\">&lt;?php<\/span>\n\n$lengths = &#91;<span class=\"hljs-number\">10<\/span>, <span class=\"hljs-number\">20<\/span>, <span class=\"hljs-number\">30<\/span>];\n\n<span class=\"hljs-comment\">\/\/ calculate areas<\/span>\n$areas = &#91;];\n\n<span class=\"hljs-keyword\">foreach<\/span> ($lengths <span class=\"hljs-keyword\">as<\/span> $length) {\n\t$areas&#91;] = $length * $length;\n}\n\nprint_r($areas);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a href=\"https:\/\/phptutorial.net\/playground\/?q=PD9waHAKCiRsZW5ndGhzID0gWzEwLCAyMCwgMzBdOwoKLy8gY2FsY3VsYXRlIGFyZWFzCiRhcmVhcyA9IFtdOwoKZm9yZWFjaCAoJGxlbmd0aHMgYXMgJGxlbmd0aCkgewoJJGFyZWFzW10gPSAkbGVuZ3RoICogJGxlbmd0aDsKfQoKcHJpbnRfcigkYXJlYXMpOw\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\n\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-keyword\">Array<\/span>\n(\n    &#91;<span class=\"hljs-number\">0<\/span>] =&gt; <span class=\"hljs-number\">100<\/span>\n    &#91;<span class=\"hljs-number\">1<\/span>] =&gt; <span class=\"hljs-number\">400<\/span>\n    &#91;<span class=\"hljs-number\">2<\/span>] =&gt; <span class=\"hljs-number\">900<\/span>\n)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>The <code>foreach<\/code> iterates over the elements of the <code>$lengths<\/code> array, calculates the area of each square, and adds the result to the <code>$areas<\/code> array.<\/p>\n\n\n\n<p>Alternatively, you can use the <code>array_map()<\/code> function that achieves the same result:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-meta\">&lt;?php<\/span>\n\n$lengths = &#91;<span class=\"hljs-number\">10<\/span>, <span class=\"hljs-number\">20<\/span>, <span class=\"hljs-number\">30<\/span>];\n\n<span class=\"hljs-comment\">\/\/ calculate areas<\/span>\n$areas = array_map(<span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-params\">($length)<\/span> <\/span>{\n\t<span class=\"hljs-keyword\">return<\/span> $length * $length;\n}, $lengths);\n\n\nprint_r($areas);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a href=\"https:\/\/phptutorial.net\/playground\/?q=PD9waHAKCiRsZW5ndGhzID0gWzEwLCAyMCwgMzBdOwoKLy8gY2FsY3VsYXRlIGFyZWFzCiRhcmVhcyA9IGFycmF5X21hcChmdW5jdGlvbiAoJGxlbmd0aCkgewoJcmV0dXJuICRsZW5ndGggKiAkbGVuZ3RoOwp9LCAkbGVuZ3Rocyk7CgoKcHJpbnRfcigkYXJlYXMpOw\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\n\n\n\n<p>In this example, the <code>array_map()<\/code> applies an <a href=\"https:\/\/phptutorial.net\/php-tutorial\/php-anonymous-functions\/\">anonymous function<\/a> to each element of the <code>$lengths<\/code> array. It returns a new array whose elements are the results of the anonymous function.<\/p>\n\n\n\n<p>From PHP 7.4, you can use an <a href=\"https:\/\/phptutorial.net\/php-tutorial\/php-arrow-functions\/\">arrow function<\/a> instead of an anonymous function like this:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-meta\">&lt;?php<\/span>\n\n$lengths = &#91;<span class=\"hljs-number\">10<\/span>, <span class=\"hljs-number\">20<\/span>, <span class=\"hljs-number\">30<\/span>];\n\n<span class=\"hljs-comment\">\/\/ calculate areas<\/span>\n$areas = array_map(\n\tfn ($length) =&gt; $length * $length,\n\t$lengths\n);\n\nprint_r($areas);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a href=\"https:\/\/phptutorial.net\/playground\/?q=PD9waHAKCiRsZW5ndGhzID0gWzEwLCAyMCwgMzBdOwoKLy8gY2FsY3VsYXRlIGFyZWFzCiRhcmVhcyA9IGFycmF5X21hcCgKCWZuICgkbGVuZ3RoKSA9PiAkbGVuZ3RoICogJGxlbmd0aCwKCSRsZW5ndGhzCik7CgpwcmludF9yKCRhcmVhcyk7\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='php-array_map-function-syntax'>PHP array_map() function syntax <a href=\"#php-array_map-function-syntax\" class=\"anchor\" id=\"php-array_map-function-syntax\" title=\"Anchor for PHP array_map() function syntax\">#<\/a><\/h2>\n\n\n\n<p>The following shows the <code>array_map()<\/code> function syntax:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">array_map ( callable|<span class=\"hljs-keyword\">null<\/span> $callback , <span class=\"hljs-keyword\">array<\/span> $array , <span class=\"hljs-keyword\">array<\/span> ...$arrays ) : <span class=\"hljs-keyword\">array<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>The <code>array_map()<\/code> has the following parameters:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>$callback<\/code> &#8211; a callable to apply to each element in each array.<\/li>\n\n\n\n<li><code>$array<\/code> &#8211; is an array of elements to which the callback function applies.<\/li>\n\n\n\n<li><code>$arrays<\/code> &#8211; is a variable list of array arguments to which the callback function applies.<\/li>\n<\/ul>\n\n\n\n<p>The <code>array_map()<\/code> function returns a new array whose elements are the result of the callback function.<\/p>\n\n\n\n<p>This tutorial focuses on the following form of the <code>array_map()<\/code> function:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">array_map ( callable $callback , <span class=\"hljs-keyword\">array<\/span> $array ) : <span class=\"hljs-keyword\">array<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\" id='using-the-php-array_map-function-with-an-array-of-objects'>Using the PHP array_map() function with an array of objects <a href=\"#using-the-php-array_map-function-with-an-array-of-objects\" class=\"anchor\" id=\"using-the-php-array_map-function-with-an-array-of-objects\" title=\"Anchor for Using the PHP array_map() function with an array of objects\">#<\/a><\/h2>\n\n\n\n<p>The following defines a class that has three properties: <code>$id<\/code>, <code>$username<\/code>, and <code>$email<\/code> and a list of <code>User<\/code> objects:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-meta\">&lt;?php<\/span>\n\n<span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">User<\/span>\n<\/span>{\n\t<span class=\"hljs-keyword\">public<\/span> $id;\n\n\t<span class=\"hljs-keyword\">public<\/span> $username;\n\n\t<span class=\"hljs-keyword\">public<\/span> $email;\n\n\t<span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">__construct<\/span><span class=\"hljs-params\">(int $id, string $username, string $email)<\/span>\n\t<\/span>{\n\t\t<span class=\"hljs-keyword\">$this<\/span>-&gt;id = $id;\n\t\t<span class=\"hljs-keyword\">$this<\/span>-&gt;username = $username;\n\t\t<span class=\"hljs-keyword\">$this<\/span>-&gt;email = $email;\n\t}\n}\n\n$users = &#91;\n\t<span class=\"hljs-keyword\">new<\/span> User(<span class=\"hljs-number\">1<\/span>, <span class=\"hljs-string\">'joe'<\/span>, <span class=\"hljs-string\">'joe@phptutorial.net'<\/span>),\n\t<span class=\"hljs-keyword\">new<\/span> User(<span class=\"hljs-number\">2<\/span>, <span class=\"hljs-string\">'john'<\/span>, <span class=\"hljs-string\">'john@phptutorial.net'<\/span>),\n\t<span class=\"hljs-keyword\">new<\/span> User(<span class=\"hljs-number\">3<\/span>, <span class=\"hljs-string\">'jane'<\/span>, <span class=\"hljs-string\">'jane@phptutorial.net'<\/span>),\n];<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>The following illustrates how to use the <code>array_map()<\/code> function to get a list of usernames from the the <code>$users<\/code> array:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-meta\">&lt;?php<\/span>\n\n<span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">User<\/span>\n<\/span>{\n\t<span class=\"hljs-keyword\">public<\/span> $id;\n\n\t<span class=\"hljs-keyword\">public<\/span> $username;\n\n\t<span class=\"hljs-keyword\">public<\/span> $email;\n\n\t<span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">__construct<\/span><span class=\"hljs-params\">(int $id, string $username, string $email)<\/span>\n\t<\/span>{\n\t\t<span class=\"hljs-keyword\">$this<\/span>-&gt;id = $id;\n\t\t<span class=\"hljs-keyword\">$this<\/span>-&gt;username = $username;\n\t\t<span class=\"hljs-keyword\">$this<\/span>-&gt;email = $email;\n\t}\n}\n\n$users = &#91;\n\t<span class=\"hljs-keyword\">new<\/span> User(<span class=\"hljs-number\">1<\/span>, <span class=\"hljs-string\">'joe'<\/span>, <span class=\"hljs-string\">'joe@phptutorial.net'<\/span>),\n\t<span class=\"hljs-keyword\">new<\/span> User(<span class=\"hljs-number\">2<\/span>, <span class=\"hljs-string\">'john'<\/span>, <span class=\"hljs-string\">'john@phptutorial.net'<\/span>),\n\t<span class=\"hljs-keyword\">new<\/span> User(<span class=\"hljs-number\">3<\/span>, <span class=\"hljs-string\">'jane'<\/span>, <span class=\"hljs-string\">'jane@phptutorial.net'<\/span>),\n];\n\n$usernames = array_map(\n\tfn ($user) =&gt; $user-&gt;username,\n\t$users\n);\n\nprint_r($usernames);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a href=\"https:\/\/phptutorial.net\/playground\/?q=PD9waHAKCmNsYXNzIFVzZXIKewoJcHVibGljICRpZDsKCglwdWJsaWMgJHVzZXJuYW1lOwoKCXB1YmxpYyAkZW1haWw7CgoJcHVibGljIGZ1bmN0aW9uIF9fY29uc3RydWN0KGludCAkaWQsIHN0cmluZyAkdXNlcm5hbWUsIHN0cmluZyAkZW1haWwpCgl7CgkJJHRoaXMtPmlkID0gJGlkOwoJCSR0aGlzLT51c2VybmFtZSA9ICR1c2VybmFtZTsKCQkkdGhpcy0-ZW1haWwgPSAkZW1haWw7Cgl9Cn0KCiR1c2VycyA9IFsKCW5ldyBVc2VyKDEsICdqb2UnLCAnam9lQHBocHR1dG9yaWFsLm5ldCcpLAoJbmV3IFVzZXIoMiwgJ2pvaG4nLCAnam9obkBwaHB0dXRvcmlhbC5uZXQnKSwKCW5ldyBVc2VyKDMsICdqYW5lJywgJ2phbmVAcGhwdHV0b3JpYWwubmV0JyksCl07CgokdXNlcm5hbWVzID0gYXJyYXlfbWFwKAoJZm4gKCR1c2VyKSA9PiAkdXNlci0-dXNlcm5hbWUsCgkkdXNlcnMKKTsKCnByaW50X3IoJHVzZXJuYW1lcyk7\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\n\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-10\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-keyword\">Array<\/span>\n(\n    &#91;<span class=\"hljs-number\">0<\/span>] =&gt; joe\n    &#91;<span class=\"hljs-number\">1<\/span>] =&gt; john\n    &#91;<span class=\"hljs-number\">2<\/span>] =&gt; jane\n)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-10\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\" id='using-a-static-method-as-a-callback'>Using a static method as a callback <a href=\"#using-a-static-method-as-a-callback\" class=\"anchor\" id=\"using-a-static-method-as-a-callback\" title=\"Anchor for Using a static method as a callback\">#<\/a><\/h2>\n\n\n\n<p>The callback function argument of the <code>array_map()<\/code> can be a public method of a class. For example:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-11\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-meta\">&lt;?php<\/span>\n\n<span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">Square<\/span>\n<\/span>{\n\t<span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-keyword\">static<\/span> <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">area<\/span><span class=\"hljs-params\">($length)<\/span>\n\t<\/span>{\n\t\t<span class=\"hljs-keyword\">return<\/span> $length * $length;\n\t}\n}\n\n$lengths = &#91;<span class=\"hljs-number\">10<\/span>, <span class=\"hljs-number\">20<\/span>, <span class=\"hljs-number\">30<\/span>];\n\n$areas = array_map(<span class=\"hljs-string\">'Square::area'<\/span>, $lengths);\n\n\nprint_r($areas);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-11\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a href=\"https:\/\/phptutorial.net\/playground\/?q=PD9waHAKCmNsYXNzIFNxdWFyZQp7CglwdWJsaWMgc3RhdGljIGZ1bmN0aW9uIGFyZWEoJGxlbmd0aCkKCXsKCQlyZXR1cm4gJGxlbmd0aCAqICRsZW5ndGg7Cgl9Cn0KCiRsZW5ndGhzID0gWzEwLCAyMCwgMzBdOwoKJGFyZWFzID0gYXJyYXlfbWFwKCdTcXVhcmU6OmFyZWEnLCAkbGVuZ3Rocyk7CgoKcHJpbnRfcigkYXJlYXMpOw\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\n\n\n\n<p>How it works.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>First, define the <code>Square<\/code> class that has the <code>area()<\/code> public static method.<\/li>\n\n\n\n<li>Second, create an array that holds the lengths of the three squares.<\/li>\n\n\n\n<li>Third, calculate the areas of the squares based on the lengths in the <code>$lengths<\/code> array using the <a href=\"https:\/\/phptutorial.net\/php-oop\/php-static-methods\/\">static method<\/a> <code>Square::area<\/code>.<\/li>\n<\/ul>\n\n\n\n<p>Note that the syntax for passing a public <a href=\"https:\/\/phptutorial.net\/php-oop\/php-static-methods\/\">static method<\/a> to the <code>array_map()<\/code> function is as follows:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-12\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-string\">'className::staticMethodName'<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-12\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>The public static method must accept the array element as an argument.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='summary'>Summary <a href=\"#summary\" class=\"anchor\" id=\"summary\" title=\"Anchor for Summary\">#<\/a><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use the PHP <code>array_map()<\/code> method to create a new array by applying a callback function to every element of another array.<\/li>\n<\/ul>\n<div class=\"helpful-block-content\" data-title=\"\">\n\t<header>\n\t\t<div class=\"wth-question\">Did you find this tutorial useful?<\/div>\n\t\t<div class=\"wth-thumbs\">\n\t\t\t<button\n\t\t\t\tdata-post=\"1090\"\n\t\t\t\tdata-post-url=\"https:\/\/www.phptutorial.net\/php-tutorial\/php-array_map\/\"\n\t\t\t\tdata-post-title=\"PHP array_map\"\n\t\t\t\tdata-response=\"1\"\n\t\t\t\tclass=\"wth-btn-rounded wth-yes-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t\tclass=\"feather feather-thumbs-up block w-full h-full\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> Yes <\/span>\n\t\t\t<\/button>\n\n\t\t\t<button\n\t\t\t\tdata-response=\"0\"\n\t\t\t\tdata-post=\"1090\"\n\t\t\t\tdata-post-url=\"https:\/\/www.phptutorial.net\/php-tutorial\/php-array_map\/\"\n\t\t\t\tdata-post-title=\"PHP array_map\"\n\t\t\t\tclass=\"wth-btn-rounded wth-no-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> No <\/span>\n\t\t\t<\/button>\n\t\t<\/div>\n\t<\/header>\n\n\t<div class=\"wth-form hidden\">\n\t\t<div class=\"wth-form-wrapper\">\n\t\t\t<div class=\"wth-title\"><\/div>\n\t\t\t\n\t\t\t<textarea class=\"wth-message\"><\/textarea>\n\n\t\t\t<button class=\"btn btn-primary wth-btn-submit\">Send<\/button>\n\t\t\t<button class=\"btn wth-btn-cancel\">Cancel<\/button>\n\t\t\n\t\t<\/div>\n\t<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, you will learn how to use the PHP array_map() function to transform array elements.<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":15,"menu_order":70,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-1090","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.phptutorial.net\/wp-json\/wp\/v2\/pages\/1090","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.phptutorial.net\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.phptutorial.net\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.phptutorial.net\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.phptutorial.net\/wp-json\/wp\/v2\/comments?post=1090"}],"version-history":[{"count":5,"href":"https:\/\/www.phptutorial.net\/wp-json\/wp\/v2\/pages\/1090\/revisions"}],"predecessor-version":[{"id":3126,"href":"https:\/\/www.phptutorial.net\/wp-json\/wp\/v2\/pages\/1090\/revisions\/3126"}],"up":[{"embeddable":true,"href":"https:\/\/www.phptutorial.net\/wp-json\/wp\/v2\/pages\/15"}],"wp:attachment":[{"href":"https:\/\/www.phptutorial.net\/wp-json\/wp\/v2\/media?parent=1090"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}