Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <ul> <li>Changing Values: <ul> <li><a href="http://php.net/array_map" rel="noreferrer"><code>array_map</code></a> cannot change the values inside input array(s) while <a href="http://php.net/array_walk" rel="noreferrer"><code>array_walk</code></a> can; in particular, <a href="http://php.net/array_map" rel="noreferrer"><code>array_map</code></a> never changes its arguments.</li> </ul></li> <li>Array Keys Access: <ul> <li><a href="http://php.net/array_map" rel="noreferrer"><code>array_map</code></a> cannot operate with the array keys, <a href="http://php.net/array_walk" rel="noreferrer"><code>array_walk</code></a> can.</li> </ul></li> <li>Return Value: <ul> <li><a href="http://php.net/array_map" rel="noreferrer"><code>array_map</code></a> returns a new array, <a href="http://php.net/array_walk" rel="noreferrer"><code>array_walk</code></a> only returns <code>true</code>/<code>false</code>. Hence, if you don't want to create an array as a result of traversing one array, you should use <a href="http://php.net/array_walk" rel="noreferrer"><code>array_walk</code></a>.</li> </ul></li> <li>Iterating Multiple Arrays: <ul> <li><a href="http://php.net/array_map" rel="noreferrer"><code>array_map</code></a> also can receive an arbitrary number of arrays and it can iterate over them in parallel, while <a href="http://php.net/array_walk" rel="noreferrer"><code>array_walk</code></a> operates only on one.</li> </ul></li> <li>Passing Arbitrary Data to Callback: <ul> <li><a href="http://php.net/array_walk" rel="noreferrer"><code>array_walk</code></a> can receive an extra arbitrary parameter to pass to the callback. This mostly irrelevant since PHP 5.3 (when <a href="http://nl3.php.net/manual/en/functions.anonymous.php" rel="noreferrer">anonymous functions</a> were introduced).</li> </ul></li> <li>Length of Returned Array: <ul> <li>The resulting array of <code>array_map</code> has the same length as that of the largest input array; <code>array_walk</code> does not return an array but at the same time it cannot alter the number of elements of original array; <a href="http://php.net/array_filter" rel="noreferrer"><code>array_filter</code></a> picks only a subset of the elements of the array according to a filtering function. It does preserve the keys.</li> </ul></li> </ul> <p>Example:</p> <pre><code>&lt;pre&gt; &lt;?php $origarray1 = array(2.4, 2.6, 3.5); $origarray2 = array(2.4, 2.6, 3.5); print_r(array_map('floor', $origarray1)); // $origarray1 stays the same // changes $origarray2 array_walk($origarray2, function (&amp;$v, $k) { $v = floor($v); }); print_r($origarray2); // this is a more proper use of array_walk array_walk($origarray1, function ($v, $k) { echo "$k =&gt; $v", "\n"; }); // array_map accepts several arrays print_r( array_map(function ($a, $b) { return $a * $b; }, $origarray1, $origarray2) ); // select only elements that are &gt; 2.5 print_r( array_filter($origarray1, function ($a) { return $a &gt; 2.5; }) ); ?&gt; &lt;/pre&gt; </code></pre> <p>Result:</p> <pre><code>Array ( [0] =&gt; 2 [1] =&gt; 2 [2] =&gt; 3 ) Array ( [0] =&gt; 2 [1] =&gt; 2 [2] =&gt; 3 ) 0 =&gt; 2.4 1 =&gt; 2.6 2 =&gt; 3.5 Array ( [0] =&gt; 4.8 [1] =&gt; 5.2 [2] =&gt; 10.5 ) Array ( [1] =&gt; 2.6 [2] =&gt; 3.5 ) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload