我有点卡在这个上,所以我认为id传递给它。
我有一个表可以动态建立,用于y轴,x轴和值的放置框。
值输入框的名称从左到右,从上到下编号。
0,1
2,3
4,5
6,7
让我们在输入框7中输入一个值,我想获得X和Y轴标题。
当构建表格由数组构建时。
[heading_x] => Array
(
[0] => red
[1] => black
)
[heading_y] => Array
(
[0] => Small
[1] => Medium
[2] => Large
[3] => X-Large
)
[value] => Array
(
[1] => Array
(
[0] =>
[1] =>
)
[2] => Array
(
[0] =>
[1] =>
)
[3] => Array
(
[0] =>
[1] =>
)
[4] => Array
(
[0] =>
[1] => foo
)
到目前为止我写的用于找到x轴和y轴的代码如下
if( preg_match( "#^([0-9]+)\-value([0-9]+)\-([0-9]?)$#is", $key, $match ) ) {
foreach( $attrDetails as $key_2 => $array ) {
if( $array['attribute_id'] == $match[1] && $val != '0' && $val != '' ) {
$options = unserialize( stripslashes( $attrDetails[$key_2]['attribute_options'] ) );
unset( $options['value'][0] );
print_r($options);
$max = count( $options['heading_x'] );
$base = $match[2] + 1;
$position_x = ( $base % $max ) + 1;
$position_y = ( ( floor( $base / $max ) - 1 ) < 0 ? 0 : floor( $base / $max ) - 1 );
if( $match[3] == '' || $base == '0' ) {
if( $pd_details->pd_activate_special_offer == '1' && $pd_details->pd_offer_price != '0.00' ) {
if( $array['attribute_type'] == '4' ) {
$cost = $val * $pd_details->pd_offer_price;
}
}else{
if( $array['attribute_type'] == '4' ) {
$cost = sprintf("%01.2f", $val * $pd_details->pd_price );
}
}
}
die($position_x . ' / ' . $position_y);
echo $options['heading_y'][$position_y-1] . ' / ' . $options['heading_x'][$position_x-1] . " amount: $val cost: $cost <br />\n";
$_SESSION['basket']['items']['top_option'][] = $options['heading_x'][$position_x-1];
$_SESSION['basket']['items']['side_option'][] = $options['heading_y'][$position_y-1];
$_SESSION['basket']['items']['amount'][] = $val;
$_SESSION['basket']['items']['price'][] = $cost;
}
}
}
主要位是
$max = count( $options['heading_x'] );
$base = $match[2] + 1;
$position_x = ( $base % $max ) + 1;
$position_y = ( ( floor( $base / $max ) - 1 ) < 0 ? 0 : floor( $base / $max ) - 1 );
posiition y似乎很好。我的问题是让我们说
楼层($ base / $ max) - 1
= 3.50。
我知道3是第三个向下(或者我忘记的关键3)如何使用余数来找到x轴?
答案 0 :(得分:1)
...没关系
$max = count( $options['heading_x'] );
$position_x=0;
$position_y=0;
for( $z=0; $z<$match[2]+1; $z++){
if( $position_x % $max == 0 ) { $position_y++; $position_x=0; }
$position_x++;
}