Skip to content

Instantly share code, notes, and snippets.

@22902902
Created January 9, 2020 13:31
Show Gist options
  • Save 22902902/357e3f7990129f12f97ebd2c923a0823 to your computer and use it in GitHub Desktop.
Save 22902902/357e3f7990129f12f97ebd2c923a0823 to your computer and use it in GitHub Desktop.
<?php
//主数组:
$a = array(
0 => array('agent_address' => '1,2,3,4'),
1 => array('agent_address' => '2'),
2 => array('agent_address' => '1,2,3,4'),
3 => array('agent_address' => '1,2,3,4'),
4 => array('agent_address' => '2'),
5 => array('agent_address' => '3'),
6 => array('agent_address' => '1,2,3,4'),
7 => array('agent_address' => '1,2'),
8 => array('agent_address' => '1,3'),
9 => array('agent_address' => '4,5'),
);
//子数组:
$b = array(
0 => array('id' => '1', 'name' => 'aaa'),
1 => array('id' => '2', 'name' => 'bbb'),
2 => array('id' => '3', 'name' => 'ccc'),
3 => array('id' => '4', 'name' => 'ddd'),
4 => array('id' => '5', 'name' => 'eee'),
);
// 测试 stristr() 函数
foreach($a as $k => $v)
{
foreach($b as $k1 => $v1)
{
if(stristr($v['agent_address'], $v1['id']))
{
$a[$k]['jm'][$v1['id']] = $v1;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment