如何将字符串反序列化为数组 [英] How to unserialize a string to array

查看:349
本文介绍了如何将字符串反序列化为数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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
)

这篇关于如何将字符串反序列化为数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆