There is an array structure like this:
array (size=3)
19 =>
array (size=4)
'pro_id' => string '44' (length=2)
'attr_id' => int 19
'attr_value' =>
array (size=1)
0 => string '12 months' (length=8)
'attr_price' =>
array (size=1)
0 => string '200' (length=3)
20 =>
array (size=4)
'pro_id' => string '44' (length=2)
'attr_id' => int 20
'attr_value' =>
array (size=1)
0 => string 'Calculated based on 5%' (length=14)
'attr_price' => null
18 =>
array (size=4)
'pro_id' => string '44' (length=2)
'attr_id' => int 18
'attr_value' =>
array (size=2)
0 => string 'Declaration without invoice 0' (length=16)
1 => string 'Declaration based on invoice amount' (length=18)
'attr_price' =>
array (size=2)
0 => string '100' (length=3)
1 => string '200' (length=3)
The data table structure is as follows:
< /p>
The result I want is as above, how should I deal with it? ? Data table structure
DROP TABLE IF EXISTS `dhd_product_attr`;
CREATE TABLE `dhd_product_attr` (
`pro_attr_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`pro_id` mediumint(8) unsigned NOT NULL DEFAULT '0',
`attr_id` smallint(5) unsigned NOT NULL DEFAULT '0',
`attr_value` text NOT NULL,
`attr_price` varchar(255) NOT NULL COMMENT 'This attribute corresponds to the price to be added to the original price of the product',
PRIMARY KEY (`pro_attr_id`),
KEY `pro_id` (`pro_id`),
KEY `attr_id` (`attr_id`)
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
How to deal with this array? ?
foreach reorganizes the array and changes it to the format corresponding to the database
I just don’t know how to reorganize this code
Simple and crude, two layers of foreach or use one layer of foreach and list function