Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: PHP
Posted by: tolik8 user
Added: Jul 7, 2018 11:59 AM
Views: 16
Tags: array_map
array_map example
  1. <?php
  2.  
  3. $users = [
  4.     [
  5.         "name" => "John",
  6.         "surname" => "Doe",
  7.         "age" => 20,
  8.         "email" => "john@example.com"
  9.     ],
  10.    
  11.     [
  12.         "name" => "Jane",
  13.         "surname" => "Doe",
  14.         "age" => 18,
  15.         "email" => "jane@example.com"
  16.     ],
  17.    
  18.     [
  19.         "name" => "Mary",
  20.         "surname" => "Doe",
  21.         "age" => 22,
  22.         "email" => "mary@example.com"
  23.     ],
  24.    
  25. ];
  26.  
  27. var_dump($users);
  28.  
  29. $func = function($item) {
  30.     return $item["email"];
  31. };
  32.  
  33. $emails = array_map($func, $users);
  34.  
  35. var_dump($emails);
  36.