gcdb::process_field_formats()
最后更新于:2021-11-26 09:03:30
gcdb::process_field_formats( array$data, mixed$format)Prepares arrays of value/format pairs as passed to gcdb CRUD methods.
参数
- $data
-
(array) (Required) Array of fields to values.
- $format
-
(mixed) (Required) Formats to be mapped to the values in $data.
响应
(array) Array, keyed by field names with values being an array of ‘value’ and ‘format’ keys.
源文件
文件: gc-includes/gc-db.php
protected function process_field_formats( $data, $format ) {
$formats = (array) $format;
$original_formats = $formats;
foreach ( $data as $field => $value ) {
$value = array(
'value' => $value,
'format' => '%s',
);
if ( ! empty( $format ) ) {
$value['format'] = array_shift( $formats );
if ( ! $value['format'] ) {
$value['format'] = reset( $original_formats );
}
} elseif ( isset( $this->field_types[ $field ] ) ) {
$value['format'] = $this->field_types[ $field ];
}
$data[ $field ] = $value;
}
return $data;
}