how to create a formula to set a priority level that decreases if the number increases

193 Views Asked by At

I'm a php programmer and I'm in the middle of a a new project that creates websites' sitemap

to create sitemap we set a propriety level for every link on the site the priority decreases if the link is away deeper and away from the home page the idea is that:

  • if the link 1 level away priority will be 1
  • if the link 2 levels away priority will be 0.80
  • if the link 3 levels away priority will be 0.75
  • if the link 4 levels away priority will be 0.64

the priority levels i mention are just for illustration all i need is a simple formula to decrease the priority while the link level increases

1

There are 1 best solutions below

0
On

i have created a function in the PHP language uses the following simple formula
$priority = 1-.120*page level ;
if the deep level is 1 the priority will be 0.88
if the deep level is 5 the priority will be 0.40
and to avoid the priority reach less than .20
i asked the function to assign the value .20 if the formula gives me a value less than that
it's very rare for a link to be away deeper than 7
the complete php function

function priority_calc ($pentration){
     $priority = 1-.120*$pentration  ;

 if ($priority < .20){
       $priority = .20;  
     }
     $priority =  number_format($priority, 2, '.', ''); // 2 decimal
     return $priority ; 
}