표시 순서로 정렬 된 제품 목록이 포함 된 제품 배열이 있습니다.제품 배열의 범주 배열
$products = array(
[0] = array(
"productID" => 189736,
"title" => "Spice Girls Album",
"category" => "CD",
"order" => "0"
),
[1] = array(
"productID" => 23087,
"title" => "Snakes on a plane",
"category" => "DVD",
"order" => "0"
),
[2] = array(
"productID" => 9874,
"title" => "The Beatles Album",
"category" => "CD",
"order" => "1"
), ... etc etc
내가 이런 종류의 배열로 돌려의 논리를 이해하려고 노력 해요 : 그래서
$categories = array(
[0] => array(
"title" => "CD",
"products" => array (
[0] => "Spice Girls Album",
[1] => "The Beatles Album"
)
),
[1] => array(
"title" => "DVD",
"products" => array (
[0] => "Snakes on a plane"
)
)
각 제품에 대한 내가 가진 :
if (!in_array($product['cateogry'], $categories)){
$categories[] = $product['cateogry'];
$categories[$product['category']][] = $product;
} else {
$categories[$product['category']][];
}
그러나이 ISN을 왜냐하면 나는 in_array가 카테고리 배열을 충분히 깊이 생각하고 있다고 생각하지 않기 때문이다. 누구든지이 문제를 해결할 수있는 가장 좋은 방법에 대한 조언이 있습니까? 많은 감사
감사합니다. – Lars