I tried this method, but it caused Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 42 bytes) in E:\www\json_example\4.php on line 170 the line in foreach foreach($data_b as $b) $arr[] =.
so in addition to the this method, is there any easy way can mixed the two FOREACH data random? less cost memory. (Not quite necessarily sort by title) Thanks.
foreach($data_a as $a){
//$a['title'];
//$a['content'];
$arr[] = array('title' => html_entity_decode($a['title'], ENT_QUOTES, 'UTF-8'),'content' => html_entity_decode($a['content'], ENT_QUOTES, 'UTF-8'));
}
foreach($data_b as $b){
//$b['title'];
//$b['content'];
$arr[] = array('title' => html_entity_decode($b['title'], ENT_QUOTES, 'UTF-8'),'content' => html_entity_decode($b['content'], ENT_QUOTES, 'UTF-8'));
}
function cmp($aa, $bb)
{
$t1 = $aa['title'];
$t2 = $bb['title'];
if ($t1 == $t2) return 0;
return $t1 < $t2 ? -1 : 1;
}
usort($arr, 'cmp');
foreach ($arr as $item){
echo $item['title'];
echo $item['content'];
}
Try to free memory as soon as you don’t need it anymore: