I have an array [0,1,2,3,4] if i got ApplicationStatus = 868 at first then it return only that value other are remove from array. My actual array and i want expected array as below. Actual Array -
Array
(
[0] => Array
(
[Name] => DENNIS VICENCIO BLANCO
[ApplicationStatus] => 826
)
[1] => Array
(
[Name] => ARPITA RANJAN DUTTA
[ApplicationStatus] => 826
)
[2] => Array
(
[Name] => MARLUNA LIM URUBIO
[ApplicationStatus] => 868
)
[3] => Array
(
[Name] => BREDJET - ALEXANDER
[ApplicationStatus] => 868
)
[4] => Array
(
[Name] => DENNIS VICENCIO BLANCO
[ApplicationStatus] => 826
)
)
Expected Array -
Array
(
[0] => Array
(
[Name] => DENNIS VICENCIO BLANCO
[ApplicationStatus] => 826
)
[1] => Array
(
[Name] => ARPITA RANJAN DUTTA
[ApplicationStatus] => 826
)
[2] => Array
(
[Name] => MARLUNA LIM URUBIO
[ApplicationStatus] => 868
)
)
So,how to remove remaining key from array.please suggest mi appropriate solution for this.
You can use array slice function:
$desired_array = array();
for($i = 0; $i < count($my_array); $i++)
{
if($my_array[$i]["ApplicationStatus"] == 868)
{
$desired_array = array_slice($my_array, 0, $i);
}
}
Not very clear, but you can delete a value from an array with unset() function. For example:
unset($arr[3]); // removes array with key = 3
...but I would use the array_filter() and would create a function to select the right elements what I need.