Idiorm
6 years ago
Paris
6 years ago
Sudzy
6 years ago
ArrayColumn.php
6 years ago
CSS.php
6 years ago
XLSXWriter.php
6 years ago
index.php
6 years ago
ArrayColumn.php
84 lines
| 1 | <?php |
| 2 | |
| 3 | namespace MailPoetVendor; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | /* |
| 9 | * Using func_get_args() in order to check for proper number of parameters and trigger errors exactly as the built-in array_column() |
| 10 | * does in PHP 5.5. |
| 11 | * @author Ben Ramsey (http://benramsey.com) |
| 12 | */ |
| 13 | function array_column($input = null, $column_key = null, $index_key = null) { |
| 14 | $argc = func_num_args(); |
| 15 | $params = func_get_args(); |
| 16 | |
| 17 | if (!empty(\array_column([['id' => '4']], 'id'))) { |
| 18 | return \array_column($input, $column_key, $index_key); |
| 19 | } |
| 20 | if ($argc < 2) { |
| 21 | trigger_error("array_column() expects at least 2 parameters, {$argc} given", E_USER_WARNING); |
| 22 | return null; |
| 23 | } |
| 24 | if (!is_array($params[0])) { |
| 25 | trigger_error( |
| 26 | 'array_column() expects parameter 1 to be array, ' . gettype($params[0]) . ' given', |
| 27 | E_USER_WARNING |
| 28 | ); |
| 29 | return null; |
| 30 | } |
| 31 | if (!is_int($params[1]) |
| 32 | && !is_float($params[1]) |
| 33 | && !is_string($params[1]) |
| 34 | && $params[1] !== null |
| 35 | && !(is_object($params[1]) && method_exists($params[1], '__toString')) |
| 36 | ) { |
| 37 | trigger_error('array_column(): The column key should be either a string or an integer', E_USER_WARNING); |
| 38 | return false; |
| 39 | } |
| 40 | if (isset($params[2]) |
| 41 | && !is_int($params[2]) |
| 42 | && !is_float($params[2]) |
| 43 | && !is_string($params[2]) |
| 44 | && !(is_object($params[2]) && method_exists($params[2], '__toString')) |
| 45 | ) { |
| 46 | trigger_error('array_column(): The index key should be either a string or an integer', E_USER_WARNING); |
| 47 | return false; |
| 48 | } |
| 49 | $params_input = $params[0]; |
| 50 | $params_column_key = ($params[1] !== null) ? (string)$params[1] : null; |
| 51 | $params_index_key = null; |
| 52 | if (isset($params[2])) { |
| 53 | if (is_float($params[2]) || is_int($params[2])) { |
| 54 | $params_index_key = (int)$params[2]; |
| 55 | } else { |
| 56 | $params_index_key = (string)$params[2]; |
| 57 | } |
| 58 | } |
| 59 | $result_array = []; |
| 60 | foreach ($params_input as $row) { |
| 61 | $key = $value = null; |
| 62 | $key_set = $value_set = false; |
| 63 | if ($params_index_key !== null && array_key_exists($params_index_key, $row)) { |
| 64 | $key_set = true; |
| 65 | $key = (string)$row[$params_index_key]; |
| 66 | } |
| 67 | if ($params_column_key === null) { |
| 68 | $value_set = true; |
| 69 | $value = $row; |
| 70 | } elseif (is_array($row) && array_key_exists($params_column_key, $row)) { |
| 71 | $value_set = true; |
| 72 | $value = $row[$params_column_key]; |
| 73 | } |
| 74 | if ($value_set) { |
| 75 | if ($key_set) { |
| 76 | $result_array[$key] = $value; |
| 77 | } else { |
| 78 | $result_array[] = $value; |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | return $result_array; |
| 83 | } |
| 84 |