我有两个数组
数组1
array (size=51)
0 =>
array (size=15)
'id' => int 1
'title' =>
array (size=1)
'fr' => string '95% des intégrateurs écrivent mal leurs titre' (length=47)
'slug' => string '95-des-integrateurs-ecrivent-mal-leurs-titre' (length=44)
'date' => string '2017-05-16 00:00:00' (length=19)
'introduction' =>
array (size=1)
'fr' => string 'Incidunt qui quod aut blanditiis velit. Aperiam eligendi et enim molestiae esse quidem. Rerum ex suscipit et rerum dolor dicta fugit. Omnis cumque libero quaerat autem aut voluptas ea. Pariatur praesentium id quia nisi quae esse incidunt et. Maxime laboriosam ex enim repellat dolorem aperiam.' (length=293)
'content' =>
array (size=1)
'fr' => string '<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla ornare arcu sapien, sit amet porttitor tortor laoreet ut. Ut accumsan augue lectus, ac auctor lorem hendrerit id. Maecenas suscipit consectetur velit, eu posuere nisl viverra a. Pellentesque vel justo scelerisque tortor vulputate consequat. Vivamus quis placerat libero. Maecenas facilisis erat at magna cursus, ac interdum nisl dictum. Sed eros arcu, lacinia ut commodo non, condimentum vitae odio. Sed at ex justo. Mauris id arcu semper, gravid'... (length=4050)
'image' => string 'http://ecoleinfographie.app/uploads/articles/da2186c4b43385f6b7ba8100b054d7be.jpg' (length=81)
'status' => string 'PUBLIÉ' (length=7)
'category_id' => int 13
'author_id' => null
'teacher_id' => int 36
'created_at' => string '2017-05-16 15:28:02' (length=19)
'updated_at' => string '2017-05-29 12:36:21' (length=19)
'deleted_at' => null
'orientation' => string 'web' (length=3)
1 =>
array (size=15)
'id' => int 2
'title' => …
.....
Array2:
array (size=5)
0 =>
array (size=3)
'url' => string '/blog/95-des-integrateurs-ecrivent-mal-leurs-titre' (length=50)
'pageTitle' => string '95% des intégrateurs écrivent mal leurs titre' (length=47)
'pageViews' => int 7
1 =>
array (size=3)
'url' => string '/blog/creer-un-paysage-vectoriel' (length=32)
'pageTitle' => string 'Créer un paysage vectoriel' (length=27)
'pageViews' => int 3
2 =>
array (size=3)
'url' => string '/blog/perferendis-expedita-et-ea-sint-repellendus-veritatis-quae-voluptas-eos' (length=77)
'pageTitle' => string 'Perferendis expedita et ea sint repellendus veritatis quae voluptas eos.' (length=72)
'pageViews' => int 3
3 =>
我想将所有basename(array2 ['pageTitle'])与array1 ['slug']进行比较,对于匹配的每个元素,我想创建一个新数组,其中包含每个元素。所以,结果应该是:
array3
'id' => int 1
'title => …
'slug' => 'my-cool-title'
'date' => …
'introduction' => …
..........
'url' => string '/blog/95-des-integrateurs-ecrivent-mal-leurs-titre'
'pageTitle' => string 'Créer un paysage vectoriel' (length=27)
'pageViews' => int 3
是否可以做类似的事情?
谢谢!
答案 0 :(得分:0)
在PHP中, 你可以这样做。
foreach($array2 as $a2){
foreach($array1['data'] as $a1){
if($a2['pageTitle'] == $a1['slug']){
<!--
populate array3 here with the data from array1 and arra2
-->
}
}
}