0

i have two tables one is recipe table and 2nd is ingrediants and i have data like this so how i merge same data i dont want recipe print multiple times..

Array
    (
        [data] => Array
            (
                [1] => Array
                    (
                        [id] => 1
                        [recipe] => tea
                        [ingrediant] => milk

                    )

                [2] => Array
                    (
                        [id] => 1
                        [recipe] => tea
                        [ingrediant] => sugar
                    )
                [3] => Array
                    (
                        [id] => 1
                        [recipe] => tea
                        [ingrediant] => water
                    )
            )
    )
Tom
  • 3,031
  • 1
  • 25
  • 33
  • Are you using SQL? If so, you'll have to do some post processing to convert your row-like results into a more structured object in PHP. – Tom Mar 09 '15 at 08:37
  • yes i am getting data from database and i made join query to get ingrediants from ingrediants table into recipe table .. –  Mar 09 '15 at 08:43

2 Answers2

0

You shouldn't just ask your problem here. First you should search thoroughly for solution and if you don't find then you are most welcome to ask here. And during asking one thing to keep in mind which is to ask a constructive question, that can include the code snippet you are trying.

I think you can find your solution here:

PHP: Merge 2 Multidimensional Arrays

or here:

PHP - merging 2D array by keys

Community
  • 1
  • 1
jishan
  • 300
  • 1
  • 4
  • 20
0
<?php
$newArr = array();
foreach($result['data'] as $key=>$value){
    if(!in_array($value, $newArr)){
        $newArr[] = $value;
    }
}
print_r($newArr);

?>
harry
  • 1,007
  • 2
  • 10
  • 19