2차원배열 질문입니다!
본문
shop.lib에서
//장바구니 간소 데이터 가져오기
function get_boxcart_datas($is_cache=false)
{
global $g5;
$cart_id = get_session("ss_cart_id");
if( !$cart_id ){
return array();
}
static $cache = array();
if( $is_cache && !empty($cache) ){
return $cache;
}
$sql = " select * from {$g5['g5_shop_cart_table']} ";
$sql .= " where od_id = '".$cart_id."' ";
$result = sql_query($sql);
for ($i=0; $row=sql_fetch_array($result); $i++)
{
$key = $row['it_id'];
$cache[$i][$key] = $row;
}
return $cache;
}
shop.lib에서 $cache[$i][$key] = $row; 이부분 [$i]를 추가해서 2차원배열형식으로 만들었습니다.
이유는 장바구니에 중복된값이 들어가야해서...인데요
boxcart.skin.php에서
$cart_datas = get_boxcart_datas(true);
요함수를 호출해서 $cart_datas 에 담고
foreach($cart_datas as $row)
{
}
boreach를 요렇게 쓰더라구요, 근데제가 $cache[$i][$key] 이부분 이차원으로 했기에
foreach문을 어떻게 써야할지 질문드립니다.
$cart_datas에 담긴 배열내용은 이렇습니다.
Array
(
[0] => Array
(
[7462236977] => Array
(
[ct_id] => 28174
[od_id] => 2019110509320256
[mb_id] => admin
[it_id] => 7462236977
[it_name] => 2019-11-08(금)
[it_sc_type] => 1
[it_sc_method] => 0
[it_sc_price] => 0
[it_sc_minimum] => 0
[it_sc_qty] => 0
[ct_status] => 쇼핑
[ct_history] =>
[ct_price] => 15000
[ct_point] => 150
[cp_price] => 0
[ct_point_use] => 0
[ct_stock_use] => 0
[ct_option] =>
[ct_qty] => 1
[ct_notax] => 0
[io_id] =>
[io_type] => 0
[io_price] => 0
[ct_time] => 2019-11-05 14:40:04
[ct_ip] =>
[ct_send_cost] => 2
[ct_direct] => 0
[ct_select] => 0
[ct_select_time] => 0000-00-00 00:00:00
[sendsms] =>
[pick_date] =>
)
)
[1] => Array
(
[1517459549] => Array
(
[ct_id] => 28176
[od_id] => 2019110509320256
[mb_id] => admin
[it_id] => 1517459549
[it_name] => 단호박죽
[it_sc_type] => 0
[it_sc_method] => 0
[it_sc_price] => 0
[it_sc_minimum] => 0
[it_sc_qty] => 0
[ct_status] => 쇼핑
[ct_history] =>
[ct_price] => 4900
[ct_point] => 40
[cp_price] => 0
[ct_point_use] => 0
[ct_stock_use] => 0
[ct_option] => :2019-11-07(목)
[ct_qty] => 2
[ct_notax] => 0
[io_id] => 2019-11-07(목)
[io_type] => 0
[io_price] => 0
[ct_time] => 2019-11-05 14:40:17
[ct_ip] =>
[ct_send_cost] => 0
[ct_direct] => 0
[ct_select] => 0
[ct_select_time] => 0000-00-00 00:00:00
[sendsms] =>
[pick_date] =>
)
)
[2] => Array
(
[1517459549] => Array
(
[ct_id] => 28175
[od_id] => 2019110509320256
[mb_id] => admin
[it_id] => 1517459549
[it_name] => 단호박죽
[it_sc_type] => 0
[it_sc_method] => 0
[it_sc_price] => 0
[it_sc_minimum] => 0
[it_sc_qty] => 0
[ct_status] => 쇼핑
[ct_history] =>
[ct_price] => 4900
[ct_point] => 40
[cp_price] => 0
[ct_point_use] => 0
[ct_stock_use] => 0
[ct_option] => :2019-11-08(금)
[ct_qty] => 2
[ct_notax] => 0
[io_id] => 2019-11-08(금)
[io_type] => 0
[io_price] => 0
[ct_time] => 2019-11-05 14:40:17
[ct_ip] =>
[ct_send_cost] => 0
[ct_direct] => 0
[ct_select] => 0
[ct_select_time] => 0000-00-00 00:00:00
[sendsms] =>
[pick_date] =>
)
)
[3] => Array
(
[8356487318] => Array
(
[ct_id] => 28173
[od_id] => 2019110509320256
[mb_id] => admin
[it_id] => 8356487318
[it_name] => 2019-11-07(목)
[it_sc_type] => 1
[it_sc_method] => 0
[it_sc_price] => 0
[it_sc_minimum] => 0
[it_sc_qty] => 0
[ct_status] => 쇼핑
[ct_history] =>
[ct_price] => 15000
[ct_point] => 150
[cp_price] => 0
[ct_point_use] => 0
[ct_stock_use] => 0
[ct_option] =>
[ct_qty] => 1
[ct_notax] => 0
[io_id] =>
[io_type] => 0
[io_price] => 0
[ct_time] => 2019-11-05 14:40:04
[ct_ip] =>
[ct_send_cost] => 2
[ct_direct] => 0
[ct_select] => 0
[ct_select_time] => 0000-00-00 00:00:00
[sendsms] =>
[pick_date] =>
)
)
)
답변 3
$cart = [];
foreach($cart_datas as $key => $value) {
foreach($value as $k => $v) {
$cart[$k] = $v['it_name'];
}
}
print_r($cart);
각 배열에대한 it_name을 가져오고싶습니다.
It_id를 뭐하러 i다음에 배열키로 만들어서 복잡하게 하는지 이해가 안되네요