Home >Backend Development >PHP Tutorial >Data table field demand_praiseid type varchar defaults to empty string. How to convert it to an array?
<code> // 添加点赞人 public function addPraisePeople($uid,$demand_id){ $demandId['demand_id'] = $demand_id; $m = D('demand'); $praiseid = $m->where($demandId)->getField('demand_praiseid'); }</code>
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
<code> // 添加点赞人 public function addPraisePeople($uid,$demand_id){ $demandId['demand_id'] = $demand_id; $m = D('demand'); $praiseid = $m->where($demandId)->getField('demand_praiseid'); }</code>
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.