匹配两个数组关联键并用第一个数组替换引用数组键
Match two array associates keys and replace reference array key with 1st array
匹配第一个和第二个数组关联键。并替换第一个数组将键与第二个数组值关联。信息如下。
1st Array
[
[ ],
[ ],
{
585: {
firsthalf: "0",
secondhalf: "1",
goals: "1",
outcome: ["loss"]
},
625: {
firsthalf: "2",
secondhalf: "2",
goals: "4",
outcome: ["win"]
}
},
{
609: {
firsthalf: "2",
secondhalf: "0",
goals: "2",
outcome: ["win"]
},
625: {
firsthalf: "0",
secondhalf: "1",
goals: "1",
outcome: ["loss"]
}
},
2nd Array
[
{654: "North Geelong Warriors FC"},
{645: "Springvale White Eagles FC"},
{637: "Brunswick City Soccer Club"},
{625: "Melbourne Victory Youth FC"},
{585: "Moreland City FC"},
最后出来应该是这样的
Final Array
[
[ ],
[ ],
{
Moreland City FC: {
firsthalf: "0",
secondhalf: "1",
goals: "1",
outcome: ["loss"]
},
Melbourne Victory Youth FC: {
firsthalf: "2",
secondhalf: "2",
goals: "4",
outcome: ["win"]
}
},
$newArray = array();
foreach($Array01 as $keys => $values){
foreach($values as $key => $value){
for ($x = 0; $x <= count($array02); $x++) {
if (array_search($key, $array02[$x])){
$newkey = array_search($key,$array02[$x]);
$newArray[] = array($newkey => $value);
}
}
}
}
print_r($$newArray);
这已经解决了。
匹配第一个和第二个数组关联键。并替换第一个数组将键与第二个数组值关联。信息如下。
1st Array
[
[ ],
[ ],
{
585: {
firsthalf: "0",
secondhalf: "1",
goals: "1",
outcome: ["loss"]
},
625: {
firsthalf: "2",
secondhalf: "2",
goals: "4",
outcome: ["win"]
}
},
{
609: {
firsthalf: "2",
secondhalf: "0",
goals: "2",
outcome: ["win"]
},
625: {
firsthalf: "0",
secondhalf: "1",
goals: "1",
outcome: ["loss"]
}
},
2nd Array
[
{654: "North Geelong Warriors FC"},
{645: "Springvale White Eagles FC"},
{637: "Brunswick City Soccer Club"},
{625: "Melbourne Victory Youth FC"},
{585: "Moreland City FC"},
最后出来应该是这样的
Final Array
[
[ ],
[ ],
{
Moreland City FC: {
firsthalf: "0",
secondhalf: "1",
goals: "1",
outcome: ["loss"]
},
Melbourne Victory Youth FC: {
firsthalf: "2",
secondhalf: "2",
goals: "4",
outcome: ["win"]
}
},
$newArray = array();
foreach($Array01 as $keys => $values){
foreach($values as $key => $value){
for ($x = 0; $x <= count($array02); $x++) {
if (array_search($key, $array02[$x])){
$newkey = array_search($key,$array02[$x]);
$newArray[] = array($newkey => $value);
}
}
}
}
print_r($$newArray);
这已经解决了。