<?php public static function reverse($input) { // Use regex to match "Array(...)" strings preg_match_all('/Array\(([^)]+)\)/', $input, $matches); $result = array(); foreach ($matches[1] as $match) { $result[] = self::parseArray($match); } return $result; } private static function parseArray($input) { // Use regex to match key-value pairs $matches = array(); preg_match_all("/\[(.+?)\] \=\> (.+)$/m", $input, $matches, PREG_SET_ORDER); $result = array(); foreach ($matches as $match) { $key = trim($match[1]); $value = trim($match[2]); // Recursively check if the value is another array $result[$key] = self::parseArray($value); } return $result; } // Example usage $input = " Array ( [0] => 20231219 [date] => 20231219 [1] => 9 [shine_id] => 9 [2] => 2 [nico_id] => 2 [3] => 無性に天下一品が食べたくなったので土曜行こうと思います。 [memo] => 無性に天下一品が食べたくなったので土曜行こうと思います。 ) Array ( [0] => 20231220 [date] => 20231220 [1] => 13 [shine_id] => 13 [2] => 2 [nico_id] => 2 [3] => 久々に8:30に出勤。いつもより長く寝れて気持ちが休みモードになりそうで怖かった。 [memo] => 久々に8:30に出勤。いつもより長く寝れて気持ちが休みモードになりそうで怖かった。 )"; $result = YourClassName::reverse($input); print_r($result);
You have javascript disabled. You will not be able to edit any code.