我正在尝试在 PHP 中转换一个巨大的配置数组,看起来像这样
$config['festival'] =
array
(
'title' => 'USF Tango Festival',
'tableLayout' => array
(
'registration' => array
(
array('firstName','text'),
array('lastName','text'),
array('phone','text'),
array('email','text'),
array('hearAboutFestival','text'),
array('danceAs','enum(\'Leader\', \'Follower\', \'Both\')'),
array('student','tinyint(1)')
),
'experience' => array
(
array('options','text'),
array('lunchMeat','enum(\'Ham\',\'Turkey\',\'Vegetarian\')'),
array('lunchBread','enum(\'White\',\'Wheat\')'),
array('dinnerPref','enum(\'Chicken\',\'Beef\',\'Vegetarian\')')
)
),
'pageLayout' => array
(
'registration' => array
(
'jqueryRules' =>
<<<EOT
'firstName': 'required',
'lastName': 'required',
'phone': {
required: true,
phoneUS: true
},
'email': {
required: true,
email: true
},
'danceAs': 'required',
'partner': 'required',
'partnerMatching': {
required: function() {
return $("input[name='partner']").val() == 0;
}
},
'partnerName': {
required: function() {
return $("input[name='partner']").val() == 1;
}
}
EOT
,
'inputs' => array
(
array
(
'type' => 'text',
'name' => 'firstName',
'fullName' => 'First Name',
'required' => true,
'separateDiv' => false
),
array
(
'type' => 'text',
'name' => 'lastName',
'fullName' => 'Last Name',
'required' => true,
'separateDiv' => false
),
array
(
'type' => 'text',
'name' => 'phone',
'fullName' => 'Phone number',
'required' => true,
'separateDiv' => false
),
array
(
'type' => 'text',
'name' => 'email',
'fullName' => 'Email address',
'required' => true,
'separateDiv' => false
),
array
(
'type' => 'text',
'name' => 'hearAboutFestival',
'separateDiv' => false,
'fullName' => 'How did you hear about the festival?',
'required' => false
),
array
(
'type' => 'select',
'name' => 'danceAs',
'fullName' => 'You dance as a...',
'required' => true,
'separateDiv' => false,
'options' => array(array('leader','Leader'),array('follower','Follower'),array('both','Both'))
),
array
(
'type' => 'checkbox',
'name' => 'student',
'value' => '1',
'separateDiv' => false,
'fullName' => 'I am a student',
'required' => false
)
)
)
和
'options' => array
(
'busMilonga' => array
(
'price' => 20,
'student' => false,
'name' => 'Tango on the Town Bus milonga',
'description' => 'A bus milonga!'
),
'thursdayMilonga' => array
(
'price' => 10,
'student' => false,
'name' => 'Thursday Kickoff Milonga',
'description' => 'The un-official kick off milonga!'
),
'saturdayPass' => array
(
'price' => 90,
'student' => true,
'name' => 'Saturday pass',
'description' => 'Includes all Saturday workshops and milongas'
),
'sundayPass' => array
(
'price' => 80,
'student' => true,
'name' => 'Sunday pass',
'description' => 'Includes all Sunday workshops, the jam session, and milonga'
),
'milongaPass' => array
(
'price' => 70,
'earlyBird' => 50, //array(50,60),
'student' => true,
'name' => 'Milonga Pass',
'description' => 'Includes entrance to all night milongas'
),
'dinnerPass' => array
(
'price' => 20,
'student' => false,
'name' => 'Dinner pass',
'description' => 'Includes Saturday dinner'
),
'lunchPass' => array
(
'price' => 10,
'student' => false,
'name' => 'Saturday lunch',
'description' => 'Includes lunch on Saturday'
)
),
'info' => array
(
'instructors' => array('Instructors'),
'hour' => array('10','11','12','01','02','03'),
'min' => array('15','30','45','00'),
'tod' => array('AM','PM'),
'day' => array('Friday','Saturday','Sunday'),
'level' => array('Beginner','Intermediate','Advanced'),
'place' => array('REC 107','REC 033','REC 005'),
'sessions' => array
(
3, // days
array
(
'Friday', // day name
3, // sessions on this day
array
(
3, // workshops in session
'1100AM' // time
),
array
(
3,
'0100PM'
),
array
(
1,
'0230PM'
) // 1,4
),
array('Saturday', // 2,0
3, // 2,1
array(1,'1030AM'), //2,2
array(3,'1145AM'), // 2,3
array(3,'0145PM') // 2,4
),
array
(
'Sunday', // 3,0
3, // 3,1
array(1,'1115AM'), // 3,2
array(3,'1230PM'), // 3,3
array(3,'0230PM') // 3,4
)
)
)
入数据库。我想我可以制作一些表格,标题类似于 config.event.festival 但随后会变得很麻烦,因为我必须为数组下的每个数组创建一个表格......
我想避免使用 JSON 编码或序列化,这样我就可以保持数据的所有相关性和干净的外观,但除了保留一个大的配置文件而不是数据库之外,我不知道任何其他方式。