codeigniter将tinyint类型记录转换为布尔值

时间:2014-09-16 05:11:15

标签: php codeigniter

是否有任何技巧可以将返回的tinyint记录类型转换为codeigniter中的boolean?

我有这个记录:

[{
    "id": "1",
    "body": "Go to store",
    "completed": "1"
}, {
    "id": "2",
    "body": "Learn Angular",
    "completed": "0"
}]

我想将已完成的属性转换为布尔值,因此结果将如下所示:

[{
    "id": "1",
    "body": "Go to store",
    "completed": true
}, {
    "id": "2",
    "body": "Learn Angular",
    "completed": false
}]

怎么做?

之前谢谢

2 个答案:

答案 0 :(得分:0)

你应该在json之外转换它,只需尝试:

$completed = ($completed === 1)

答案 1 :(得分:0)

试试这个:

foreach($yourjsondata as $j)
    $j['completed'] = ($j['completed'] === "1");