我有一个名为产品属性的表,我想在其中一一存储产品属性名称及其值。例如,用户选择价格作为属性名称,并选择 100,200,300 作为其值,那么我想将价格与产品 ID 一起存储为 100、200 和 300。我有这样的数组:-
[attribute_name] => Array
(
[0] => Color
[1] => weight
[2] => Brand
[3] => Price
)
[Attrvalue] => Array
(
[0] => Black
[1] => 2kg
[2] => 3kg
[3] => 4kg
[4] => Sony
[5] => Samsung
[6] => LG
[7] => 500
[8] => 1000
[9] => 2000
[10] => 9000
[11] => 9500
[12] => 10000
)
如何像 php 中的 color=>Black 一样以键值对的形式划分此数组?
最佳答案
您可以像这样命名您的表单输入 attr[attrname] 例如 对于单值属性 用于多值属性使用
<select name="attr['price'][]" multiple>
<option>...</option>
</select>
这将为您提供一个类似的数组
array('attr'
=>array('color'=>value),
=>array(
'price'=>array(
0=>value1,
1=>value2
)
)
);
关于php - 将数组作为值存储在mysql中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28621985/