知道为什么这个 php 数组不能正常工作

any idea why this php array won't work properly

我正在使用电报机器人 api 为我的业务目的制作一个机器人,在我的项目中,我需要将机器人发送的数据存储到一个文件中,然后使用这些数据,我的问题是我可以'查询bot给出的数组 下面是我的数组,例如我想访问 message_id

在我访问 message_id 的脚本中,我写了这段代码:

$my_array = file_get_content('log');
echo $my_array['result']['message_id']

但是不行。

Array
(
    [ok] => 1
    [result] => Array
        (
            [message_id] => 599
            [from] => Array
                (
                    [id] => 224181375
                    [first_name] => boofeh
                    [username] => boofehbot
                )

            [chat] => Array
                (
                    [id] => 50408323
                    [first_name] => MOƎIN
                    [username] => imoein1
                    [type] => private
                )

            [date] => 1466751591
            [text] => اکنون سفارش خود را ارسال کنید
        )

)

你是serializing the array before writing it to the file?
And unserializing从文件中读取后得到的吗?

下面是如何序列化和反序列化数组,

$serialized_string = serialize($array);

这就是序列化数组的方式。

反序列化,

$serialized_string = file_get_contents('log');
$array = unserialize($serialized_string);
print_r($array);

现在您可以像这样访问数组中的数据,

echo $my_array['result']['message_id'];

serialize() generates a storable representation of a value

unserialize() takes a single serialized variable and converts it back into a PHP value.

http://php.net/manual/en/function.serialize.php
http://php.net/manual/en/function.unserialize.php