Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRM_Utils_Array - Implement pathUnset() method #20787

Merged
merged 1 commit into from
Jul 7, 2021

Conversation

totten
Copy link
Member

@totten totten commented Jul 6, 2021

Overview

Add a helper function, pathUnset(), which removes an item from an array-tree. This complements existing helper functions pathGet(), pathIsset(), and pathSet() (which read and write values in an array-tree).

Technical Details

For example, suppose you have this array:

$arr = [
  'one' => '1',
  'two' => [
    'half' => 2,
  ],
  'three' => [
    'first-third' => '1/3',
    'second-third' => '2/3',
  ],
];

You may interact with the item three.first-third by calling:

CRM_Utils_Array::pathGet($arr, ['three', 'first-third']); // Returns string "1/3"
CRM_Utils_Array::pathIsset($arr, ['three', 'first-third']); // Returns bool "true"
CRM_Utils_Array::pathSet($arr, ['three', 'first-third'], "Revival!"); // Updates the item
CRM_Utils_Array::pathUnset($arr, ['three', 'first-third']); // Removes the item

@civibot
Copy link

civibot bot commented Jul 6, 2021

(Standard links)

@eileenmcnaughton
Copy link
Contributor

I think the case that this is consistent with existing functions + the unit test is fairly compelling

@eileenmcnaughton
Copy link
Contributor

unrelated intermittent fail

@eileenmcnaughton eileenmcnaughton merged commit 73bd44d into civicrm:master Jul 7, 2021
@totten totten deleted the master-path-unset branch July 7, 2021 01:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants