0

i have array look like bellow

Array
(
    [0] => Array
        (
            [REDUNDANT] => NO
            [FILE_NAME] => 51894a (2).pdf
        )
    [1] => Array
        (
            [REDUNDANT] => YES
            [FILE_NAME] => book (2).pdf
        )
    [2] => Array
        (
            [REDUNDANT] => YES
            [FILE_NAME] => samae (1).pdf
        )
    [3] => Array
        (
            [REDUNDANT] => NO
            [FILE_NAME] => aswss (1).pdf
        )        
)

i want to remove all element with array[INDEX][REDUNDANT] == 'YES'

after delete the array new array look like below

Array
(
    [0] => Array
        (
            [REDUNDANT] => NO
            [FILE_NAME] => 51894a (2).pdf
        )
    [1] => Array
        (
            [REDUNDANT] => NO
            [FILE_NAME] => aswss (1).pdf
        )        
)

please help to find solution for me thanks

3 Answers 3

1

Try this,

foreach($files as $key => $file){
   if($file['REDUNDANT'] == "Yes"){
       unset($files[$key]);
   }
}
$files = array_values($files); // Reset key of updated array.

Codepad Demo.

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

Comments

1

try this

   $abc= Array
   (
        [0] => Array
        (
              [REDUNDANT] => NO
            [FILE_NAME] => 51894a (2).pdf
            )
      [1] => Array
    (
        [REDUNDANT] => YES
        [FILE_NAME] => book (2).pdf
    )
[2] => Array
    (
        [REDUNDANT] => YES
        [FILE_NAME] => samae (1).pdf
    )
[3] => Array
    (
        [REDUNDANT] => NO
        [FILE_NAME] => aswss (1).pdf
    )        
)

      foreach($abc as $subKey => $subArray){
      if($subArray['REDUNDANT'] =='yes'){
           unset($abc[$subKey]);
        }
     }

   print_r($abc);

Comments

0
foreach($yourary as $key=>$value)
{
  if($value[REDUNDANT]=="YES")
  {
   unset($yourary[$key]);
  }
}

Comments

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.