Say I have this array
$aych = array( 'B', 'B', 'A', 'A', 'B', 'A', 'A', 'B', 'B', 'A' );
and when i do a print_r right now i get...
Array ( [0] => B [1] => B [2] => A [3] => A [4] => B [5] => A [6] => A [7] => B [8] => B [9] => A )
now what i need to happen is, loop through ALL keys in the array and check if there values are B, if they are, then remove it from the array and shift everything forward.
foreach ( $aych as $key => $value )
{
if ( preg_match( '{B}', $value ) )
{
array_splice( $aych, $value, 0 );
}
}
i was able to loop through them all, and check if the value is B, as shown above. I know you use the array_splice function for this, but im not exactly sure how to properly utilize this in this environment.
in the end, if i print_r it, i need to get
Array ( [0] => A [1] => A [2] => A [3] => A [4] => A )
which is after all of the B's are removed and the array moved foward. does anyone know how to do this?