Erase some results from the array

0

I need to leave in the array below only the values Yes: 1 and 2 Any suggestion? I tried unset () but it did not work.

array (size=3)
  0 => 
    array (size=4)
      0 => string 'Adair' (length=26)
      1 => string '498' (length=3)
      2 => string 'Nao' (length=3)
      3 => string '' (length=0)
  1 => 
    array (size=4)
      0 => string 'Pedro' (length=31)
      1 => string '189' (length=3)
      2 => string 'Sim' (length=3)
      3 => string '' (length=0)
  2 => 
    array (size=4)
      0 => string 'Celso' (length=11)
      1 => string '651' (length=3)
      2 => string 'Sim' (length=3)
      3 => string 'E-mail: sdsd' (length=12)
    
asked by anonymous 25.04.2017 / 02:42

1 answer

0

Use the array_filter function with an anonymous function to return the items that contain the desired value.

Examples

If the value "Yes" is always in position 2 of the subarray:

$novoArray = array_filter($seuArray, function($arr) {
    return $arr[2] == 'Sim';
})

If you are in any position:

$novoArray = array_filter($seuArray, function($arr) {
    return in_array('Sim', $arr);
});
    
25.04.2017 / 02:58