I have two tables.
1) products : id,name,price
2) books : id,title,book_price
Now I want to merge the data of these two tables and sort them by lowest price using arrays.
How can I merge these two arrays ?
It should be something like this:
<?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));
?>
$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
or,
$output = $a1 + $a2;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.