Data table field demand_praiseid type varchar defaults to empty string. How to convert it to an array?

WBOY
Release: 2016-07-06 13:52:48
Original
1219 people have browsed it

<code> // 添加点赞人
    public function addPraisePeople($uid,$demand_id){
        $demandId['demand_id'] = $demand_id;
        $m = D('demand');
        $praiseid = $m->where($demandId)->getField('demand_praiseid');

        
    }</code>
Copy after login
Copy after login

I posted a demand that no one has posted. When I like it, I need to take out the demand_praiseid field of the demand and convert it into an array. Save the uid into the array and then convert the array into json and save it into this field

I haven’t finished it after working on it for a day. I don’t know if I think this project is too complicated

Reply content:

<code> // 添加点赞人
    public function addPraisePeople($uid,$demand_id){
        $demandId['demand_id'] = $demand_id;
        $m = D('demand');
        $praiseid = $m->where($demandId)->getField('demand_praiseid');

        
    }</code>
Copy after login
Copy after login

I posted a demand that no one has posted. When I like it, I need to take out the demand_praiseid field of the demand and convert it into an array. Save the uid into the array and then convert the array into json and save it into this field

I haven’t finished it after a day of work. I don’t know if I think this project is too complicated

First of all, after understanding your question, you should ask:
There is a data table field with a varchar type. After you use PHP to get the value of this field, how do you convert the value of this field into an array? ?
Secondly: If you want to convert the content of demand_praiseid into an array, this must be done according to the structure of your demand_praiseid.
PHP has a function to convert a string into an array:
explode(separator,string,limit)
Parameter Description: separator: required. Specifies where to split the string.
string: required. The string to split.
limit: optional. Specifies the number of array elements to be returned. Possible values: Greater than 0 - Returns an array containing up to limit elements Less than 0 - Returns an array containing all but the last -limit elements 0 - Returns an array containing one element
Hope this helps, though I don't seem to understand your needs.

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