Search code examples
phparraysperformancebinaryfiles

PHP associative array to binary file


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?


Solution

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