如何将字符串反序列化为数组

如何将字符串反序列化为数组

问题描述:

这可能不是堆栈溢出的适当问题,因此我提前致歉。我遵循另一个人的代码,遇到了这个奇怪的值数组。

This may not be an appropriate question for stack overflow so I apologize in advance. I am following behind another persons code and I came across this odd array of values.

a:2:{i:0;s:2:"25";i:1;s:2:"26";}

好像 a 值说明了项目数,然后有一个 i 值和一个 s 的值。我从未见过这种情况,也不完全确定该如何处理。在化妆之前,我只是想知道这是否是我不熟悉的某种标准。

Seems like the a value states the number of items, then there is an i value and an s value. I have never seen this and not entirely sure how to approach it. Before I make something up I was just wondering if this is some kind of standard I am not familiar with.

这是一个序列化字符串,应使用此功能反序列化

This is a serialized string you should unserialize it using this function unserialize.

<?php
ini_set('display_errors', 1);
$string='a:2:{i:0;s:2:"25";i:1;s:2:"26";}';
print_r(unserialize($string));

输出:

Array
(
    [0] => 25
    [1] => 26
)