I have an array say :
$input = Array
(
[2] => Array
(
[message] => 1 file(s) do not conform to the xxx naming standards.
[type] => warning
[headers] => Array
(
[0] => Array
(
[name] => Package
[property] => zip
)
[1] => Array
(
[name] => Name
[property] => name
)
)
[rows] => Array
(
[0] => Array
(
[zip] => abcd.zip
)
)
)
[111] => Array
(
[message] => Invalid it is
[type] => error
[headers] => Array
(
[0] => Array
(
[name] => ID
[property] => id
)
[1] => Array
(
[name] => Title
[property] => title
)
[2] => Array
(
[name] => Zip
[property] => zip
)
)
[rows] => Array
(
[0] => Array
(
[id] => abcd
[title] => title
[zip] => abcd
)
)
)
)
Then I calculate length as below : $length = count($this->view->feedback); $i= 0;
Now I am running a foreach loop as
foreach ($input as $operation)
{
if($operation['type'] == 'error')
{
$output = array_slice($operation, -$i, $length);
}
$i++;
}
The above array_slice() method outputs as below :
$output =
Array
(
[rows] => Array
(
[0] => Array
(
[id] => 214501
[title] => SRM- 3860(Res-2)
[zip] => SRM-3860(Test_2).zip
)
)
)
My DESIRED/REQUIRED output is :
$output =
Array
(
[111] => Array
(
[message] => Invalid it is
[type] => error
[headers] => Array
(
[0] => Array
(
[name] => ID
[property] => id
)
[1] => Array
(
[name] => Title
[property] => title
)
[2] => Array
(
[name] => Zip
[property] => zip
)
)
[rows] => Array
(
[0] => Array
(
[id] => abcd
[title] => title
[zip] => abcd
)
)
)
)
How can I achieve this ? Is something wrong with my array_slice method ?