高分请圣人指点 stdClass Object 转数组

WBOY
Release: 2016-06-13 11:54:44
Original
852 people have browsed it

高分请高人指点 stdClass Object 转数组
请大哥指点一下,Google不到答案就来发帖麻烦大家了.高分奉上!
问题:
我用json得来的一个数组$array 格式如下

<br />Array<br />(<br />    [0] => stdClass Object<br />        (<br />            [num_iid] => 6000026492<br />        )<br /> <br />    [1] => stdClass Object<br />        (<br />            [num] => 6000026308<br />        )<br /> <br />    [2] => stdClass Object<br />        (<br />            [num] => 6000025528<br />        )<br /> <br />    [3] => stdClass Object<br />        (<br />            [num] => 6000025650<br />        )<br /> <br />    [4] => stdClass Object<br />        (<br />            [num] => 6000027082
Copy after login

我想要得到的数组为
$array[0]=6000026492
$array[1]=6000026308
.................
请问怎么转换
尽量不用for,因为数据非常多,调用频繁,有没有最好用的方式转换.




------解决方案--------------------
提供个思路:你把json串,发出来,建议直接处理json串。比如说用一些正则表达式之类的,或者简单点的就str_replace。
------解决方案--------------------

本帖最后由 xuzuning 于 2011-07-27 08:29:46 编辑 //你接收的应该是形如这样的json数据
$s = '[{"num":123},{"num":456}]';
$t = json_decode($s, 1);//解码时宜强制转换成数组
//然后对数组降维
$p = array_map('current', $t);
//最后连接成串
echo implode(',', $p);
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!