php Размер массива в байтах bytes
Primary tabs
Для поверхностной оценки можно исползовать код вроде:
<?php function getSize($arr) { $tot = 0; foreach($arr as $a) { if (is_array($a)) { $tot += getSize($a); } if (is_string($a)) { $tot += strlen($a); } if (is_int($a)) { $tot += PHP_INT_SIZE; } } return $tot; } $arr = [ // наш массив 'link' => '/photo-223440367_457656004', 'platforms' => [1, 2] ]; echo getSize($arr); echo "\n"; // for multidimensional array // JSON_PRETTY_PRINT | JSON_FORCE_OBJECT for multiline json formatting $json = json_encode($arr, JSON_FORCE_OBJECT); echo mb_strlen($json, '8bit') . " bytes\n"; // output - 61 bytes
- Log in to post comments
- 410 reads