Consider this array:
$userBookmarks = [
[
"id": 10000,
"dateAdded": 1552127606
],
[
"id": 20000,
"dateAdded": 1552127610
],
[
"id": 30000,
"dateAdded": 1552127614
]
]
Suppose I know the ID is 10000 and I want to remove the child array where the value of id
is 10000, what is the most efficient way so I can remove the entire child array and be left with this:
$userBookmarks = [
[
"id": 20000,
"dateAdded": 1552127610
],
[
"id": 30000,
"dateAdded": 1552127614
]
]
My "closest" attempt:
for( $i = 0; $i < count( $userBookmarks ); $i++ ) {
$currentBookmark = $userBookmarks[ $i ];
if( $currentBookmark['id'] == $newBookmarkID ) {
unset( $currentBookmark );
break;
} else {
$userBookmarks[] = $newBookmark;
}
}
But it's really not doing anything...