0

I have a file with logs into which arrays of this format are written.

How can I get arrays in which the [timestamp] range will be from 2021-05-01 to 2021-05-10?

Thank you so much!

Array
(
     [event] => message
     [timestamp] => 2021-05-18
     [chat_hostname] => SN-CHAT-14_
     [message_token] => 557539925623
     [sender] => Array
         (
             [id] => swvhGP / 0WK8GmEccowg ==
             [api_version] => 10
         )

     [message] => Array
         (
             [text] => konf
             [type] => text
         )

     [silent] => 1
)
Array
(
     [event] => message
     [timestamp] => 2021-05-17
     [chat_hostname] => SN-CHAT-14_
     [message_token] => 5575369991822565
     [sender] => Array
         (
             [id] => swvhGP / 0WK4SEccowg ==
         )

     [message] => Array
         (
             [text] => www
             [type] => text
         )

     [silent] => 1
)
Gwyneth Llewelyn
  • 796
  • 1
  • 11
  • 27
  • 5
    Storing them like this was a bad choice. PHP can't parse this with any built-in functions. You can have a look at [this question](https://stackoverflow.com/questions/7025909/how-create-an-array-from-the-output-of-an-array-printed-with-print-r), where a solution was posted to turn `print_r` into an actual array. For long term sustainability, I would recommend turning this into a JSON file. Reading and storing into it is a trivial task. – El_Vanja May 19 '21 at 12:51
  • @El_Vanja logs in json, I thought it would be easier to get the necessary information from the array can you tell me how to get it with json? `{"event": "message", "timestamp": 1614672537791, "chat_hostname": "SN-CHAT-02 _", "message_token": 55474483857330347, "sender": {"id": "9Vji3TpwMbFEoMKInhfA ==", "name ":" Yuliya "," avatar ":" https "," language ":" uk "," country ":" "," api_version ": 10}," message ": {" text ":" yes "," type ":" text "}," silent ": true}` – Андрийко Александр May 19 '21 at 17:55
  • Ah, so you're actually writing JSON to file? So what you've shown in the question was just a dump of the decoded JSON? – El_Vanja May 19 '21 at 18:22
  • @ El_Vanja yes, sorry for my stupidity) – Андрийко Александр May 19 '21 at 19:45
  • In that case, [`array_filter`](https://www.php.net/manual/en/function.array-filter.php) will be enough. – El_Vanja May 19 '21 at 19:49

0 Answers0