5

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"
}
1
  • You can't assign a value to a function. Fix your code first. Commented Feb 23, 2012 at 22:40

2 Answers 2

13
$row_dailyNotes['note'] .= 'text to append';
Sign up to request clarification or add additional context in comments.

Comments

5

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;

3 Comments

isnt that appending to the key not the value?
@user1222646 - No, $key .= "sometext" would append to the key.
@user1222646: That is appending to the value, not the key. See php.net/Array

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.