-1

I have a lot of array data, and it takes a lot of space to store in plain php script. It might take a while to read the script and store it in memory. So I wanna try save the data in binary format, but I have no any idea how that works

How can I save multi dimension associative array like

$var = array(
  array('name'=> 'name1', 'age' => 23),
  array('name'=> 'name2', 'age' => 23),
  ...
);

to a binary file? and read it again in another script?

Bonn
  • 53
  • 1
  • 13
  • If your file needs to read the array then pack it... or unpack the binary then read it... how does the extra step save memory? – Ryan Tuosto Apr 09 '17 at 02:54
  • well, im not sure too. Im trying to find a solution to speed up dealing with large arrays – Bonn Apr 09 '17 at 05:14
  • http://stackoverflow.com/questions/6336528/memory-optimization-in-php-array – Ryan Tuosto Apr 09 '17 at 05:15
  • i kinda interested with method here http://stackoverflow.com/questions/11702192/php-and-the-million-array-baby but i dont know the multidimension array equivalent – Bonn Apr 09 '17 at 05:22

1 Answers1

0

You can use php pack, unpack function to do it.

Nick Jang
  • 239
  • 4
  • 3