I have an associative array like this
$arrz1=Array([sss] => Array
(
[0] => 315
[1] => 330
[2] => 345
[3] => 315
[4] => 330
[5] => 345
[6] => 360
[7] => 315
[8] => 330
[9] => 345
[10] => 360
[11] => 375
)
[fff] => Array
(
[0] => 315
[1] => 330
[2] => 345
[3] => 315
[4] => 330
[5] => 345
[6] => 360
[7] => 315
[8] => 330
[9] => 345
[10] => 360
[11] => 375
[12] => 750
[13] => 765
[14] => 780
)
)
I want to achieve this.Provided array size can variate and every next should not have the previous all element :
Array([0] => Array
(
[0] => Array
(
[0] => 315
[1] => 330
[2] => 345
[3] => 315
[4] => 330
[5] => 345
[6] => 360
[7] => 315
[8] => 330
[9] => 345
[10] => 360
[11] => 375
)
)
[1] => Array
(
[0] => Array
(
[0] => 750
[1] => 765
[2] => 780
)
)
Need to figure out the best least time complexity feasible solution.So ,the result fetched is fast enough to achieve result in respective deadline.So far i have tried following
$array_key = array();
$array_val = array();
$mult = array();
foreach ($arrz1 as $key => $val) {
$diff = array();
foreach($val as $val1)
{
if(!in_array($val1, $array_val))
{
$diff[] = $val1;
}
}
if(!in_array($key, $array_key))
{
$array_key[] = $key;
//print_r($diff);
if(!empty($diff))
{
$mult[] = array($diff);
foreach($val as $value)
{
$array_val[] = $value;
}
}
else
{
$mult[] = array($val);
foreach($val as $value)
{
$array_val[] = $value;
}
}
}
}
The result is correct but time is too much
array_diff()orarray_diff_assoc()depending on your requirements.