2阵列之间的关系 [英] relationship between 2 arrays
问题描述
我有所有联系人数组,我有所有组的数组。
我怎么能代替 http://www.google.com/m8/feeds/groups/j**/base/3166d58a8c**25
与组名的YouTube
触点阵列吗?
由于谷歌联系人API V3的确组名存储为一个id,我想与组的名称来取代这个ID。
例如
阵列组:
阵列(2){
[0] =>
阵列(3){
[值] =>
串(87)http://www.google.com/m8/feeds/groups/**/base/***b87ad92
[名称] =>
串(4)家庭
[标签] =>
串(4)家庭
}
[1] =>
阵列(3){
[值] =>
串(87)http://www.google.com/m8/feeds/groups/j**/base/3166d58a8c**25
[名称] =>
字符串(7)YouTube的视频
[标签] =>
字符串(7)YouTube的视频
}
}
阵列联系方式:
阵列(250){
[0] =>
阵列(8){
[值] =>
串(15),X Y
[名称] =>
串(15),X Y
[电子邮件] =>
串(25)blabla@gmail.com
[电话] =>
串(10)044564
[团] =>
串(87)http://www.google.com/m8/feeds/groups/j**/base/3166d58a8c**25
[phonework] =>
串(10)0479 // 804
[地址] =>
串(28),55222之城
[标签] =>
串(15)布拉
}
......
}
最后的结果将是:
阵列(250){
[0] =>
阵列(8){
[值] =>
串(15),X Y
[名称] =>
串(15),X Y
[电子邮件] =>
串(25)blabla@gmail.com
[电话] =>
串(10)044564
[团] =>
串(87)YouTube的视频
[phonework] =>
串(10)0479 // 804
[地址] =>
串(28),55222之城
[标签] =>
串(15)布拉
}
......
}
只要创建一个嵌套循环。循环触头第一(其将被覆盖),则它里面的基团。内环内,只是让相等比较:
的foreach($为&放大器联系; $触点){
//参考^
的foreach($组为$组){
如果($联络['组'] == $组['值']){
$联系['组'] = $组['名'];
}
}
}
I have an array with all contacts and I have an array with all groups.
How can I replace http://www.google.com/m8/feeds/groups/j**/base/3166d58a8c**25
with the group name YouTube
in the contact array?
Since Google Contacts API v3 does store the group name as an id, I want to replace this id with the name of the group.
E.g.
Array groups:
array(2) {
[0]=>
array(3) {
["value"]=>
string(87) "http://www.google.com/m8/feeds/groups/**/base/***b87ad92"
["name"]=>
string(4) "Family"
["label"]=>
string(4) "Family"
}
[1]=>
array(3) {
["value"]=>
string(87) "http://www.google.com/m8/feeds/groups/j**/base/3166d58a8c**25"
["name"]=>
string(7) "YouTube"
["label"]=>
string(7) "YouTube"
}
}
Array Contacts:
array(250) {
[0]=>
array(8) {
["value"]=>
string(15) "X Y"
["name"]=>
string(15) "X Y"
["email"]=>
string(25) "blabla@gmail.com"
["phone"]=>
string(10) "044564"
["group"]=>
string(87) "http://www.google.com/m8/feeds/groups/j**/base/3166d58a8c**25"
["phonework"]=>
string(10) "0479//804"
["address"]=>
string(28) "55222 City"
["label"]=>
string(15) "Bla"
}
......
}
Final output would be:
array(250) {
[0]=>
array(8) {
["value"]=>
string(15) "X Y"
["name"]=>
string(15) "X Y"
["email"]=>
string(25) "blabla@gmail.com"
["phone"]=>
string(10) "044564"
["group"]=>
string(87) "YouTube"
["phonework"]=>
string(10) "0479//804"
["address"]=>
string(28) "55222 City"
["label"]=>
string(15) "Bla"
}
......
}
Just create a nested loop. Loop the contacts first (which will be overwritten), then inside it the groups. Inside the inner loop, just make an equality comparison:
foreach($contacts as &$contact) {
// ^ reference
foreach($groups as $group) {
if($contact['group'] == $group['value']) {
$contact['group'] = $group['name'];
}
}
}
这篇关于2阵列之间的关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!