我想通过从数据库中获取数据来制作多维数组。创建了由特定用户添加的播客的第二个数组,但是,它没有提供数据库中处于活动状态的另一个用户的输出。
这是我的代码:
def range_subset(range1, range2):
return (range1[0]>=range2[0] and range1[1]<=range2[1])
for key in dict1.keys():
if key in dict2.keys():
print(key)
print(range_subset(dict1[key], dict2[key]))
print('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')
答案 0 :(得分:1)
您需要建立一个数据列表。将数据创建为1项将停止将podcast
数据与fullname
...
$userList = $user->getAllUserName();
$data = [];
foreach ($userList as $users) {
$fullname = $users->first_name. ' '. $users->last_name;
$data[] = array(
'name' => $fullname,
'podcast' => $podcast->getUserPodcast($fullname)
);
}
仅限于具有播客的用户...
$userList = $user->getAllUserName();
$data = [];
foreach ($userList as $users) {
$fullname = $users->first_name. ' '. $users->last_name;
$podcast = $podcast->getUserPodcast($fullname);
if ( !empty($podcast) ) {
$data[] = array(
'name' => $fullname,
'podcast' => $podcast
);
}
}