国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

After converting PHP array to object, how to access data using object?
給我你的懷抱
給我你的懷抱 2017-05-16 13:15:05
0
3
551
    $fields = M('fields') -> select();
    $aa = json_encode($fields);
    $bb = json_decode($aa);
    
    $bb -> 0;//獲取不到任何數(shù)據(jù),應該怎么寫呢
    
    print_r($bb);
    結果為:

Array
(

[0] => stdClass Object
    (
        [fields_id] => 1
        [name] => 勘探
    )

[1] => stdClass Object
    (
        [fields_id] => 2
        [name] => 鉆完井
    )

[2] => stdClass Object
    (
        [fields_id] => 3
        [name] => 采油采氣
    )

[3] => stdClass Object
    (
        [fields_id] => 4
        [name] => 油氣儲運
    )

[4] => stdClass Object
    (
        [fields_id] => 5
        [name] => 地面工程
    )

[5] => stdClass Object
    (
        [fields_id] => 6
        [name] => 銷售煉化
    )

[6] => stdClass Object
    (
        [fields_id] => 7
        [name] => 新能源
    )

[7] => stdClass Object
    (
        [fields_id] => 8
        [name] => 綜合
    )

)

How to get the data inside? Ask for a way to write. For example, how to get all the data under [0]? What if we take [name] below [0]
?

給我你的懷抱
給我你的懷抱

reply all(3)
phpcn_u1582

There is a slight problem upstairs, let me do this: $bb[0]->

You may want to use it like this: json_decode($aa, true);

Please check the documentation when programming:

API

json_decode

(PHP 5 >= 5.2.0, PECL json >= 1.2.0, PHP 7)

json_decode — Decode JSON formatted strings

Instructions

mixed json_decode ( string $json [, bool $assoc = false [, int $depth = 512 [, int $options = 0 ]]] )
Accepts a JSON encoded string and converts it to a PHP variable

Parameters

json
The string in json string format to be decoded.

This function can only handle UTF-8 encoded data.

Note:

PHP implements a superset of JSON as specified in the original ? RFC 7159.

assoc
When this parameter is TRUE, an array will be returned instead of an object.

漂亮男人
$bb ->[0]['name'];一樣,跟普通數(shù)組類似,就是多了->
洪濤

$bb[0]->name

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template