加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

使用php进行字符串转换

发布时间:2020-12-13 21:51:31 所属栏目:PHP教程 来源:网络整理
导读:我有一个像下面这样的字符串…… Array ([product_name] = this is a product [product_desc] = some descripyion [cat_id] = 3) 这看起来像一个数组,但这是一个字符串.如果我使用echo,它会打印相同的结果. $someVariable = "Array ([product_name] = this i
我有一个像下面这样的字符串……

Array ([product_name] => this is a product [product_desc] => some descripyion [cat_id] => 3)

这看起来像一个数组,但这是一个字符串.如果我使用echo,它会打印相同的结果.

$someVariable = "Array ([product_name] => this is a product [product_desc] => some descripyion [cat_id] => 3)";

echo $someVariable;

结果:

Array ([product_name] => this is a product [product_desc] => some descripyion [cat_id] => 3)

我需要它转换为数组,以便我可以执行以下操作..

echo $someVariable['product_name'];

并得到以下结果

this is a product

有没有办法做到这一点?

谢谢

解决方法

serialize数据:

<input type="hidden" name="data" valaue='<?php print_r(serialize($yourData));?>'>

然后unserialize

<?php 
    $youralldata = unserialize($_POST['data']);
    print_r($youralldata);
?>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读