[英]Object type array elements php
I stored some values in db
using json_encode
.Now on fetching i got values like this ["ab","cd"]
.I have tried by exploding
, json_encode
and then decode.But nothing works.some of tried code is below 我使用json_encode
在db
存储了一些值。现在,在获取时,我得到了类似["ab","cd"]
。我尝试通过exploding
, json_encode
然后进行解码。但是没有任何效果。
$array = "["ab","cd"]";
$value = (array)$array;
//-------------
$array = (array) $array;
// get_object_vars
$array = get_object_vars($object);
print_r($array);
when i loop directly on array i didn't get any values.Thanks for any help in advance. 当我直接在数组上循环时,我没有任何值。感谢事先的任何帮助。 on this i got like this : 在此我得到这样的:
var_dump(json_decode($object));
print_r($object);
OUTPUT : 输出:
NULL ["MKD","KD3"]
If I am understanding your question, I think you are looking for json_decode . 如果我了解您的问题,我认为您正在寻找json_decode 。
$json_encoded_str = '["ab","cd"]';
// Will return an array of elements in your string
var_dump(json_decode($json_encoded_str));
The result would be 结果将是
array(2) {
[0]=> string(2) "ab"
[1]=> string(2) "cd"
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.