简体   繁体   中英

How to append text to specific php array value

I need to find certain keys in an array created by a MySQL query, once I have that key, I need to append some text to the value that the key is linked to

Ive figured out how to identify the key value with array_key_exists... I just need the code to append text to the associated value of the key

if(array_key_exists("note", $row_dailyNotes))
{
    // stuck here
    $row_dailyNotes(value) = $row_dailyNotes(value)."text to append"
}
$row_dailyNotes['note'] .= 'text to append';

Probably what you're looking for is:

$array[$key] = $array[$key] . "text to append";

This uses the array syntax to look up a value or set a value in a PHP "array".

Example:

$array["something"] = $array["something"] . "blah blah";

There's also a short form using .= (the string concatenating operator ):

$array[$key] .= "text to append;

我想你应该像这样使用连接运算符:

$row_dailyNotes[$key] .= "text to append";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM