1 回答
TA贡献1871条经验 获得超13个赞
如果您想将title设为keys.
$data = [
'Ludo Bagman' => 'Head of the Department of Magical Games and Sports within the Ministry of Magic.',
'Bathilda Bagshot' => 'Author of A History of Magic, and the great aunt of Gellert Grindelwald.',
'Katie Bell' => 'Gryffindor Quidditch Chaser one year above Harry Potter. Member of Dumbledore\'s Army.',
'Cuthbert Binns' => 'Ghost, History of Magic professor.',
];
$keys = [0,1,3,6];
$keyedData = array_combine($keys, $data);
// ...
foreach ($paragraphs as $key => $paragraph) {
if (in_array($key, $keys)) {
$paragraph->get('field_links')->setValue([
'title' => $keyedData[$key],
]);
$paragraph->save();
}
}
如果您将来需要这些名称:
$keyedNames = array_combine($keys, array_keys($data));
- 1 回答
- 0 关注
- 82 浏览
添加回答
举报