我有一个识别我的 $schema 的函数,
根据我的 $schema['replace'] 它替换值。
我的功能失败了。不按预期工作。
任何人都可以帮助我吗?完成我的功能
$schema = array(
array(
'tag' => 'div',
'class' => 'lines',
'repeat' => array(
'tag' => 'div',
array(
'tag' => 'span',
'style' => 'margin:10px; padding:10px',
'key' => 'title',
),
'key' => 'subject',
)
)
);
$repeat = array('Country Name' => 'Usa', 'City Name' => 'Newyork');
function repeat($schema, $repeat){
foreach($schema as $k => $v){
if($k == 'repeat'){
foreach($repeat as $rk => $rv){
$repeat[] = array_replace($schema,array_fill_keys(array_keys($schema, 'title'),$rk));
$repeat[] = array_replace($schema,array_fill_keys(array_keys($schema, 'subject'),$rv));
}
}
}
unset($schema[0]['repeat']);
$schema['repeat'] = $repeat;
return $schema;
}
print_r(repeat($schema, $repeat));
预期输出
Array
(
[0] => Array
(
[tag] => div
[class] => lines
[0] => Array
(
[tag] => div
[0] => Array
(
[tag] => span
[style] => margin:10px; padding:10px
[key] => Country Name
)
[key] => Usa
)
[1] => Array
(
[tag] => div
[0] => Array
(
[tag] => span
[style] => margin:10px; padding:10px
[key] => City Name
)
[key] => Newyork
)
)
)
我的功能有什么问题?