我有一个以下数组结构,我该如何处理它以删除所有连续出现的 change_status。请查看下面的数组,然后查看我想要实现的目标。
$a=array(
"0" => array( "status_change" => "start", "clock_status" => "1" ),
"1" => array( "status_change" => "stop", "clock_status" => "2" ),
"2" => array( "status_change" => "stop", "clock_status" => "2" ),
"3" => array( "status_change" => "stop", "clock_status" => "2" ),
"4" => array( "status_change" => "stop", "clock_status" => "2" ),
"5" => array( "status_change" => "stop", "clock_status" => "2" ),
"6" => array( "status_change" => "stop", "clock_status" => "2" ),
"7" => array( "status_change" => "start", "clock_status" => "1" ),
"8" => array( "status_change" => "stop", "clock_status" => "2" ),
"9" => array( "status_change" => "start", "clock_status" => "1" ),
"10" => array( "status_change" => "start", "clock_status" => "1" ),
"11" => array( "status_change" => "start", "clock_status" => "1" ),
"12" => array( "status_change" => "start", "clock_status" => "1" )
);
处理完上述数组后,我想要以下
$a=array(
"0" => array( "status_change" => "start", "clock_status" => "1" ),
"1" => array( "status_change" => "stop", "clock_status" => "2" ),
"7" => array( "status_change" => "start", "clock_status" => "1" ),
"8" => array( "status_change" => "stop", "clock_status" => "2" ),
"9" => array( "status_change" => "start", "clock_status" => "1" )
);
任何想法将不胜感激。我确实有一个处理一维数组的代码,但这让我感到困惑,而且在处理数组时我有点慢。