如何将文本追加到特定的php数组值

时间:2012-02-23 22:30:19

标签: php arrays append

我需要在MySQL查询创建的数组中找到某些键,一旦我有了该键,我需要将一些文本追加到该键链接的值

我已经想出如何使用array_key_exists识别键值...我只需要代码即可 将文本附加到键的关联值

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

3 个答案:

答案 0 :(得分:10)

$row_dailyNotes['note'] .= 'text to append';

答案 1 :(得分:3)

您正在寻找的可能是:

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

这使用数组语法在PHP“数组”中查找值或设置值。

示例:

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

还有一个使用.=string concatenating operator)的简短表单:

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

答案 2 :(得分:0)

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

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