Linked Questions

161 votes
6 answers
194k views

I want to loop through an array with foreach to check if a value exists. If the value does exist, I want to delete the element which contains it. I have the following code: foreach($...
ajsie's user avatar
  • 80.1k
139 votes
6 answers
271k views

I have a collection which I want to iterate and modify while I fetch some of its elements. But I could't find a way or method to remove that fetched element. $selected = []; foreach ($collection as ...
Skeletor's user avatar
  • 3,443
12 votes
11 answers
40k views

Here is print_r output of my array: Array ( [0] => stdClass Object ( [itemId] => 560639000019 [name] => Item no1 [code] => 00001 [qty] => 5 [...
Milan's user avatar
  • 1,029
1 vote
2 answers
2k views

so long story short - unsetting works fine when trying to unset $this->models[$modelKey] in first foreach, $this->models[$modelKey]->equipmentList->equipment[$eqKey] points to the correct ...
Maciej Jaśniaczyk's user avatar
2 votes
5 answers
230 views

I have an array like this : array() { ["AG12345"]=> array() { } ["AG12548"]=> array() { } ["VP123"]=> array() { } I need to keep only arrays with keys which begin ...
bahamut100's user avatar
  • 1,847
0 votes
3 answers
113 views

Simple question; How can i delete the right Array from my foreach() ? foreach ( $items as $e): if ( $e['seat'] == $users[$clientID]['seat']): //It's done, delete it. unset ( $e ); ...
Anders Hedeager's user avatar
1 vote
1 answer
271 views

I have a foreach loop that iterates through an array but I want to check if the array contains $item == 'survey-east-upper' and if that's true then hide the previous $item which is 'survey-east'. I've ...
ShambalaG's user avatar
  • 356
0 votes
1 answer
205 views

I've seen a few questions and the ones worth referencing How can i delete object from json file with PHP based on ID How do you remove an array element in a foreach loop? How to delete object from ...
Tiago Peres's user avatar
  • 15.9k
0 votes
3 answers
65 views

I get some data from the database, which is saved in "$Data". $Data looks like this: [Data] => Array ( [0] => Array ( ...
StefanK's user avatar
  • 23
1 vote
1 answer
63 views

<ul> <?php foreach (array_slice($items, 0, 3) as $item): ?> <?php if (!isset($item->story)): ?> <!-- hide story updates --> <li> <?...
Collins's user avatar
  • 1,159
-1 votes
2 answers
53 views

is there a way to loop through an array and unset any variables that are =""? i am looking for a faster way to do this aside form writing 4 if else statements.i thought this might work but i don't ...
sstokes's user avatar