我试图将某个数组中的某些项输入到另一个数组中,但是在创建该数组时,它不断添加不应该输入的项,例如
array(
$parentcat ('id' =>'1000', 'name' => 'assets',)
('id' => '2000', 'name' => 'expenses'),
$categories('id' => '1100', 'name' =>'cash', ‘cat’ => 1000)
('id' => '1200', 'name' => 'AR', ‘cat’ => 1000)
('id' => '2100', 'name' => 'AP', ‘cat’ => 2000)
('id' => '2200', 'name' => 'payroll', ‘cat’ => ‘2000’))
我尝试遍历每个数组并检查
for($k = 0; $k < count($parentCat); $k++) {
for ($j = 0; $j < count($categories); $j++) {
//echo $parentCat[$k]['id'] . ' ' . $categories[$j]['cat'];
if ($parentCat[$k]['id'] == $categories[$j]['cat']) {
//echo $categories[$j]['cat'] . '==' . $parentCat[$k]['id'];
$categories_dropdown[$categories[$j]['id']] = $categories[$j]['name'];
}
$parent[$parentCat[$k]['name']] = $categories_dropdown;
}
}
我想要这个
$parentcat('assets' => array('id' =>'1100', 'name' => 'cash'),('id' =>'1200' 'name' => 'AR'),
'expenses' => array('id' => '2100', 'name' => 'AP'),('id' => '2200' 'name' => 'payroll))
for some reason i get
$parentcat('assets' => array('id' => '1100', 'name' => 'cash'),('id'=> '1200'
'name' => 'AR'),
'expenses' => array('id' => '1100' => 'cash'),('id' =>'1200','name' => 'AR'),('id' => '2100', 'name' => 'AP'),('id' => '2200', 'name' => 'payroll))
繁星点点滴滴
牛魔王的故事