Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Adrián Vera
Adrián Vera

Posted on • Edited on

     

Replace recursively only empty array values

Hey fellow coders, i need your assistance! (please send help)

lets say i got array A and array B:

A = [
'personal_data' => [ A => ['test' => A]],
'family_data' => [ A => ['test' => A]],
];

B = [
'personal_data' => '',
'family_data' => [ B => ['test' => B]],
'payment_info' => []
];

i got to replace the data from array A with array B having a preference over array A. (need to replace A with B:
if keys don't exist add them
if key exists and value differs replace value
if key exists and value does not differ do nothing)

i.e:

A = [
'personal_data' => '',
'family_data' => [
A => ['test' => A]
B => ['test' => B]
],
'payment_info' => []
];

Top comments(2)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss
CollapseExpand
 
kushal-niroula profile image
Kushal Niroula

From what you describe, shouldn't the resulting array have personal_data as empty string, as the second array would overwrite it?

CollapseExpand
 
medadrian profile image
Adrián Vera
  • Joined
• Edited on• Edited

Yes, you are right, i already commented on the problem

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

  • Joined

Trending onDEV CommunityHot

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp