Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
I have array:
$array = array('aaa', 'bbb', 333, 'ddd', 555, '666');
I would like remove all values where key is > 3;
How is the best way for this?
$array = array_slice($array, 0, 3);
Add a comment
You can use array_slice() see documentation here.
You can use foreach loop
foreach($array as $key => $image) { if($value > 3) { unset($array[$key]); } }
array_splice($array, 3);
May be it will be the easiest way.
Required, but never shown
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.
Explore related questions
See similar questions with these tags.