<?php
$recent_projects = [
[
'project_title' => 'Project Name1',
'project_url' => 'url1'
],
[
'project_title' => 'Project Name2',
'project_url' => 'url2'
],
[
'project_title' => 'Project Name3',
'project_url' => 'url3'
],
[
'project_title' => 'Project Name4',
'project_url' => 'url4'
],
[
'project_title' => 'Project Name5',
'project_url' => 'url5'
]
];
$show_x_projects = 3; // How may projects to show
$current_page = trim($_SERVER['REQUEST_URI'], '/');
// remove the project which matches with page url
$filtered_projects = array_filter($recent_projects, function ($project) use ($current_page) {
return ($project['project_url'] != $current_page);
});
// select random 3 project from filtered projects
$random_projects = array_rand($filtered_projects, $show_x_projects);
foreach ($random_projects as $index) {
$item = $filtered_projects[$index];
echo $item['project_title']."--";
}
preferences:
45.42 ms | 406 KiB | 5 Q