0

I have the following array

Array ( 
[0] => 1_09122012070025_img1_L.jpg 
[1] => 1_09122012070025_img_L.jpg 
[2] => 1_09122012070025_img2_S.jpg 
[3] => 1_09122012070025_img1_S.jpg 
[4] => 1_09122012070025_img_S.jpg 
[5] => 1_09122012070025_img2_L.jpg 
)

I'm trying to unset the values which have S, so that I'm left with keys 0, 1, 5

1 Answer 1

2
<?php
$array = Array(
    '1_09122012070025_img1_L.jpg',
    '1_09122012070025_img_L.jpg',
    '1_09122012070025_img2_S.jpg',
    '1_09122012070025_img1_S.jpg',
    '1_09122012070025_img_S.jpg',
    '1_09122012070025_img2_L.jpg'
);


foreach($array as $k=>$a){
    if(preg_match("/_S.jpg/",$a)){
        unset($array[$k]);
    }
}

echo '<pre>';
print_r($array);
echo '</pre>';?>

Note: I matched against "_S.jpg", whereas you could just match against "S".

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you Samuel, that did the job perfect.

Your Answer

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.

Ask question

Explore related questions

See similar questions with these tags.