I have multidimensional array :
array (size=4)
0 =>
array (size=3)
'a' => string '' (length=0)
'b' => string '222.000' (length=8)
'id' => string '7' (length=1)
1 =>
array (size=3)
'a' => string '61100' (length=0)
'b' => string '1000.000' (length=8)
'id' => string '6' (length=1)
2 =>
array (size=3)
'a' => string '61100' (length=5)
'b' => string '-1000.000' (length=7)
'id' => string '4' (length=1)
I want to get the value of 'id' of arrays that contain the same 'a' value, in this case i want to get the value of 'id' of arrays 1 & 2 because both having the same value of 'a' so i want to get they id (4 & 6)
Thanks for your replies
You can do it with simple for
loop :
$arr = array(["id" => 7, "a" => ""], ["id" => 6, "a" => "AAA"], ["id" => 4, "a" => "AAA"]);
$ans = [];
foreach($arr as $elem)
$ans[$elem["a"]][] = $elem["id"];
This will output associative array with the "a" value as keys - if you only want to group them you can use array_values
.
Output:
Array
(
[] => Array
(
[0] => 7
)
[AAA] => Array
(
[0] => 6
[1] => 4
)
)