Simple Procedure: abcd accounts for 10%, 20%, 30%, 40%, and abcd10 respectively.
The income sequence of the four abcd projects accounts for 10%, 20%, 30%, and 40% respectively. If a project does not exist, the income of the project is the same as that of the previous project. Project a always exists, encapsulate a function to get the benefits of abcd;
This question is not difficult. The key point is to use arrays. If you think about it, you can do it.
Program code:
<? Php
/**
* Obtain project benefits
* @ Param null $ B
* @ Param null $ c
* @ Param null $ d
* @ Return array
*/
Function getIncome ($ B = null, $ c = null, $ d = null)
{
$ Income = ['A' => 0.1, 'B' => 0.2, 'c' => 0.3, 'D' => 0.4];
If (! $ D ){
$ Income ['C'] + = $ income ['D'];
$ Income ['D'] = 0;
}
If (! $ C ){
$ Income ['B'] + = $ income ['C'];
$ Income ['C'] = 0;
}
If (! $ B ){
$ Income ['a'] + = $ income ['B'];
$ Income ['B'] = 0;
}
Return $ income;
}
Echo '<pre> ';
Var_dump (getIncome (1, 0, 0 ));
?>