$value) { if ($key !== ++$check) { $list = false; break; } } if ($list) { $return .= 'l'; foreach ($data as $value) { $return .= self::encode($value); } } else { $return .= 'd'; foreach ($data as $key => $value) { $return .= self::encode(strval($key)); $return .= self::encode($value); } } $return .= 'e'; } elseif (is_integer($data)) { $return = 'i' . $data . 'e'; } else { $return = strlen($data) . ':' . $data; } return $return; } /** * Given a path to a file, decode the contents of it * * @param string $path * @return mixed */ public static function load($path) { if (is_file($path)) { return self::decode(file_get_contents($path)); } return null; } /** * Given a path for a file, encode the contents of it * * @param string $path * @param $data * @return mixed */ public static function dump($path, $data) { return file_put_contents($path, self::encode($data)); } }