PHP: Search Multi-Dimensional(nested) array and export values of currenly worked on array.

Hi All,

I'm writing a nagios check that will see if our ldap servers are in sync...

I got the status data into a nested array, I would like to search key [3] of each array and if "OK" is NOT present, echo other key=>values in the current array to a variable

so...eg...let take the single array below..

[1] => Array
(
[0] => dc=prvt,dc,dc=com
[1] => mldap.wst1.com:389
[2] => sldap1.wst1.com:389
[3] => OK <--- if this value is anything other then OK, $repstat .= echo " Slave server '$data2[1][2]' is not in sync with master server '$data2[1][2]'\n";
[4] => Last
[5] => update:
[6] => today
[7] => at
[8] => 6:16
[9] => AM
)

I would like to do the above process to all arrays listed below, basicly export this....
( $repstat .= echo " Slave server '$data2[1][2]' is not in sync with master server '$data2[1][2]'\n"; )
for all arrays who's key[3] value is anything other than OK, if they are all OK, then just do....
( $repstat = echo "ALL LDAP SERVER IN SYNC"; )

here is my code so far that just get the data into the nested arrays..

<?php
$command='cat ./dat';
exec  ( $command  , $output , $return_var );
foreach($output as $lines){
$cleaned[] = preg_replace('/\s+/',' ',$lines);
}
foreach($cleaned as $lines){
$data2[] = explode(" ", $lines);
if(is_array($data2)){
foreach($data2 as $key => $value){
if(is_null($value) || $value == ""){
unset($data2[$key]);
}
}
}
}
print_r($data2);
?>

root@mldap[bin]$ /opt/coolstack/php5/bin/php -f ./replcheck.php
Array
(
[0] => Array
(
[0] => dc=prvt,dc,dc=com
[1] => mldap.wst1.com:389
[2] => sldap2.wst1.com:389
[3] => OK
[4] => Last
[5] => update:
[6] => today
[7] => at
[8] => 6:16
[9] => AM
)

[1] => Array
(
[0] => dc=prvt,dc,dc=com
[1] => mldap.wst1.com:389
[2] => sldap1.wst1.com:389
[3] => OK
[4] => Last
[5] => update:
[6] => today
[7] => at
[8] => 6:16
[9] => AM
)

[2] => Array
(
[0] => dc=prvt,dc,dc=com
[1] => mldap.wst1.com:389
[2] => sldap1.qprvt.com:389
[3] => OK
[4] => Last
[5] => update:
[6] => today
[7] => at
[8] => 6:16
[9] => AM
)

[3] => Array
(
[0] => dc=prvt,dc,dc=com
[1] => mldap.wst1.com:389
[2] => sldap3.qprvt.com:389
[3] => OK
[4] => Last
[5] => update:
[6] => today
[7] => at
[8] => 6:16
[9] => AM
)

[4] => Array
(
[0] => dc=prvt,dc,dc=com
[1] => mldap.wst1.com:389
[2] => sldap1.sprvt.com:389
[3] => OK
[4] => Last
[5] => update:
[6] => today
[7] => at
[8] => 6:16
[9] => AM
)

[5] => Array
(
[0] => dc=prvt,dc,dc=com
[1] => mldap.wst1.com:389
[2] => sldap2.qprvt.com:389
[3] => OK
[4] => Last
[5] => update:
[6] => today
[7] => at
[8] => 6:16
[9] => AM
)

[6] => Array
(
[0] => dc=prvt,dc,dc=com
[1] => mldap.wst1.com:389
[2] => sldap3.wst1.com:389
[3] => OK
[4] => Last
[5] => update:
[6] => today
[7] => at
[8] => 6:16
[9] => AM
)

[7] => Array
(
[0] => dc=prvt,dc,dc=com
[1] => mldap.wst1.com:389
[2] => sldap2.sprvt.com:389
[3] => OK
[4] => Last
[5] => update:
[6] => today
[7] => at
[8] => 6:16
[9] => AM
)

[8] => Array
(
[0] => o.com
[1] => mldap.wst1.com:389
[2] => sldap1.wst1.com:389
[3] => OK
[4] => Last
[5] => update:
[6] => today
[7] => at
[8] => 6:16
[9] => AM
)

[9] => Array
(
[0] => o.com
[1] => mldap.wst1.com:389
[2] => sldap2.sprvt.com:389
[3] => OK
[4] => Last
[5] => update:
[6] => today
[7] => at
[8] => 6:16
[9] => AM
)

[10] => Array
(
[0] => o.com
[1] => mldap.wst1.com:389
[2] => sldap1.sprvt.com:389
[3] => OK
[4] => Last
[5] => update:
[6] => today
[7] => at
[8] => 6:16
[9] => AM
)

[11] => Array
(
[0] => o.com
[1] => mldap.wst1.com:389
[2] => sldap2.wst1.com:389
[3] => OK
[4] => Last
[5] => update:
[6] => today
[7] => at
[8] => 6:16
[9] => AM
)

[12] => Array
(
[0] => o.com
[1] => mldap.wst1.com:389
[2] => sldap2.qprvt.com:389
[3] => OK
[4] => Last
[5] => update:
[6] => today
[7] => at
[8] => 6:16
[9] => AM
)

[13] => Array
(
[0] => o.com
[1] => mldap.wst1.com:389
[2] => sldap3.qprvt.com:389
[3] => OK
[4] => Last
[5] => update:
[6] => today
[7] => at
[8] => 6:16
[9] => AM
)

[14] => Array
(
[0] => o.com
[1] => mldap.wst1.com:389
[2] => sldap1.qprvt.com:389
[3] => OK
[4] => Last
[5] => update:
[6] => today
[7] => at
[8] => 6:16
[9] => AM
)

[15] => Array
(
[0] => o.com
[1] => mldap.wst1.com:389
[2] => sldap3.wst1.com:389
[3] => OK
[4] => Last
[5] => update:
[6] => today
[7] => at
[8] => 6:16
[9] => AM
)

)
root@mldap[bin]$

Check if this helps

$flag = 1; # if flag is 1 then it means all are ok
$ok_msg = "ALL LDAP SERVER IN SYNC";
$not_ok_msg = '';

foreach ($data2 as $key => $arr){
        if ($arr[3] != "OK"){
                $flag = 0;
                $not_ok_msg .= "...."; # add the msg that needs to be printed
        }
}
($flag == 1) ?  print "$ok_msg" : print "$not_ok_msg";