0

Hi I would like to split an array based on its value. Say for example my array is like this

 Array
(
 [0] => Array
    (
        [id] => 1
        [amount] => 800
        [detail] => bus fare
        [student_id] => 16
        [class_id] => 1
        [bill_id] => 5a6c176b0b27a
        [total] => 1800
    )

[1] => Array
    (
        [id] => 2
        [amount] => 1000
        [detail] => tast
        [student_id] => 16
        [class_id] => 1
        [bill_id] => 5a6c176b0b27a
        [total] => 1800
    )

[2] => Array
    (
        [id] => 3
        [amount] => 5000
        [detail] => tution
        [student_id] => 16
        [class_id] => 1
        [bill_id] => 5a6d3a1d67feb
        [total] => 5150
    )

[3] => Array
    (
        [id] => 4
        [amount] => 150
        [detail] => busfare
        [student_id] => 16
        [class_id] => 1
        [bill_id] => 5a6d3a1d67feb
        [total] => 5150
    )

) I would like to split the array in bill_id basis. Means array with same bill id must come under one section. Please help me to achieve this.

4
  • 4
    What You Have tried to achieve this. Commented Jan 29, 2018 at 6:57
  • What do you mean by under one section? Whats your expected output? Commented Jan 29, 2018 at 7:05
  • Please add your expected output so that community can provide better solution in quick time. Commented Jan 29, 2018 at 7:07
  • means first arrays with same bill_id here it is first three. these should be in an array. Commented Jan 29, 2018 at 7:09

1 Answer 1

0

That's call group by, check this link

$bill_id = Arrays::groupBy($actual_array, Functions::extractField('bill_id'));

Hope this helps you.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.