0
// Source
Array
(
    [name] => ben
    [country] => ca
    [msg] => Array
        (
            [type] => mail
            [read] => 0
            [content] => hello world
        )
 )
// Change 
Array
(
    [msg] => Array
        (
            [read] => 1
        )
)
// Result
Array
(
    [name] => ben
    [country] => ca
    [msg] => Array
        (
            [type] => mail
            [read] => 1
            [content] => hello world
        )
)
$result = php_function($source,$change);

What php function allows this kind of transformation?

2
  • If all you're trying to do is change one field, why now $source['msg']['read'] = 1;? Is $change the new value of read? or is it the field to change? If it's the field does it always get set to 1? Will it always be withing message? Need some clarity here. Commented Jul 14, 2011 at 6:04
  • Hi imoda, the example you see here was simplified. I use php function to directly manipulate json objects stored in mysql. for ex: dbUpdate("tableName",$array,"where id =1") . where array could be $array = array("data"=>array("read"=>"1")). I'd want my function to update mysql in such a way that only this variable is change ... hope this clarify a little : ) - it kinda emulate noMysql shema like mongoDB but using mysql. Commented Jul 14, 2011 at 6:15

1 Answer 1

1

the function you are looking for is array_merge_recursive_simple()

See the comment to the php.net documentation of array_merge_resursive

Edit: This one is more elegant.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you ! While its not a built-in function. It sure will do the trick.
Edit is shorter but, if you want foolproof, go with the original ;)

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.