D
D
darknet372017-03-25 12:08:47
PHP
darknet37, 2017-03-25 12:08:47

How to compress a large associative array and then iterate over it. PHP?

There is such a large array, it can be even larger.

$array = array(
    "1.5 сп" => [
        'color' => [
            'Зеленый' => 'green',
            'Черный' => 'black',
        ],
        'price' => '250'
    ],
    "2 сп" => [
        'color' => [
            'Зеленый' => 'green',
            'Черный' => 'black',
        ],
        'price' => '250'
    ],
    "3 сп" => [
        'color' => [
            'Зеленый' => 'green',
            'Черный' => 'black',
        ],
        'price' => '350'
    ],
    "4 сп" => [
        'color' => [
            'Зеленый' => 'green',
            'Черный' => 'black',
        ],
        'price' => '150'
    ],
);

Then I translate it into an associative array to store it in the database.
$string = serialize($array);
It turns out this big line:
a:4:{s:8:"1.5 сп";a:2:{s:5:"color";a:2:{s:14:"Зеленый";s:5:"green";s:12:"Черный";s:5:"black";}s:5:"price";s:3:"250";}s:6:"2 сп";a:2:{s:5:"color";a:2:{s:14:"Зеленый";s:5:"green";s:12:"Черный";s:5:"black";}s:5:"price";s:3:"250";}s:6:"3 сп";a:2:{s:5:"color";a:2:{s:14:"Зеленый";s:5:"green";s:12:"Черный";s:5:"black";}s:5:"price";s:3:"350";}s:6:"4 сп";a:2:{s:5:"color";a:2:{s:14:"Зеленый";s:5:"green";s:12:"Черный";s:5:"black";}s:5:"price";s:3:"150";}}

Is there any way to compress it?
How then to sort it out?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Frank, 2017-03-25
@darknet37

php.net/manual/ru/function.gzcompress.php
ruseller.com/lessons.php?id=699&rub=37
Serialization of a large array of numbers with compression

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question