使用数组合并两个不同的表

时间:2014-02-07 05:11:27

标签: php arrays merge

我有两张桌子。

1)产品:id,名称,价格

2)书籍:id,title,book_price

现在我想合并这两个表的数据,并使用数组按最低价格对它们进行排序。

如何合并这两个数组?

它应该是这样的:

<?php
$a1=array( 
            "id"=>1,"name"=>'Ram',"price"=>100 ,
            "id"=>2,"name"=>'Keyboard',"price"=>200 ,
            "id"=>3,"name"=>'Mouse',"price"=>300 ,
            "id"=>4,"name"=>'LCD',"price"=>400 ,

            );


$a2=array( 
            "id"=>1,"title"=>'ABC',"book_price"=>150 ,
            "id"=>2,"title"=>'XYZ',"book_price"=>250 ,

            );


print_r(array_merge($a1,$a2));
?> 

1 个答案:

答案 0 :(得分:0)

$a2=array( 
            "id"=>1,"title"=>'Regions',"book_price"=>150 ,
            "id"=>2,"title"=>'Routes',"book_price"=>250 ,

            );

$a1=array( 
            "id"=>1,"name"=>'Ram',"price"=>100 ,
            "id"=>2,"name"=>'Keyboard',"price"=>200 ,
            "id"=>3,"name"=>'Mouse',"price"=>300 ,
            "id"=>4,"name"=>'LCD',"price"=>400 ,

            ); +a2

,或者

$ output = $ a1 + $ a2;