我有一个像下面这样的字符串...
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);
?>
关于php - 使用php将字符串转换为数组,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23868135/