How to filter out array elements with keys that are negative integers in PHP?
So if I have an array:
Array (
[-3] => Academic degree
[-4] => Academic discipline
[-5] => African American history
[-6] =>
[1] => Art
)
the result would be: Array ( [1] => Art ).
My idea was to use something like this:
$arr = array( ‘-1’ => 1, ‘-2’ => 2, ‘3’ => 3,
‘element4’ => 4 ); $filterOutKeys = array( ‘-1’, ‘-2’ );$filteredArr = array_diff_key( $arr, array_flip( $filterOutKeys ) )
but it turned up as very impractical when dealing with bigger arrays.
Use a simple foreach?