On the problem of dealing with arrays

now there are many arrays like this

{"content":{"productId":112640,"name":"H480g","images":["1.jpg","2.jpg","3.jpg"],"price":"33.50","brandId":5280,"brandName":"","cateId":689,"cateName":"","cateIdLevel2":686,"cateNameLevel2":"","cateIdLevel1":685,"cateNameLevel1":""}}

where
cateIdLevel1 is the first-level classification ID corresponding name cateNameLevel1
cateIdLevel2 is the second-level classification ID corresponding name cateNameLevel2
cateId is the third-level classification corresponding name cateName

now the final array that you want to achieve is
first-level classification, second-level classification, second-level classification, third-level classification, third-level classification, and these goods are in the third-level classification.

because of the large amount of data, how to implement it with the least amount of computation?

Php
Dec.15,2021

Save the corresponding data with an object that has been id as the key value, and cycle through


twice.
$str = '[{"content":{"productId":112640,"name":"H480g","images":["1.jpg","2.jpg","3.jpg"],"price":"33.50","brandId":5280,"brandName":"","cateId":689,"cateName":"","cateIdLevel2":686,"cateNameLevel2":"","cateIdLevel1":685,"cateNameLevel1":""}},{"content":{"productId":112641,"name":"22222222222","images":["1.jpg","2.jpg","3.jpg"],"price":"33.50","brandId":5280,"brandName":"","cateId":689,"cateName":"","cateIdLevel2":686,"cateNameLevel2":"","cateIdLevel1":685,"cateNameLevel1":""}},{"content":{"productId":112642,"name":"333333333","images":["1.jpg","2.jpg","3.jpg"],"price":"33.50","brandId":5280,"brandName":"","cateId":689,"cateName":"","cateIdLevel2":686,"cateNameLevel2":"","cateIdLevel1":68,"cateNameLevel1":""}}]';
$arr = json_decode($str, true);
$res = array();
$arr = array_map(function($v) use(&$res) {
    $res[$v['content']['cateIdLevel1']][$v['content']['cateIdLevel2']][$v['content']['productId']] = $v;
}, $arr);

echo json_encode($res);

if it's a string of this form, use an array_map. If there are n strings like the one you wrote, use array_merge, and then array_map

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1eabb40-47e3a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1eabb40-47e3a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?