Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // function createCondition($want, $condition = [])
- // {
- // foreach($condition as $con){
- // echo $a = $want.$con."\n";
- // // if(){
- // }
- // }
- $array = [
- [
- "id" => 1,
- "name" => "กระเบื้องธรรมดา ปูธรรมดา A",
- "case" => 0,
- "condition" => "less_than_or_equal_to",
- "condition_value" => 10,
- "labor" => 5400
- ],
- [
- "id" => 2,
- "name" => "กระเบื้องธรรมดา ปูธรรมดา A",
- "case" => 0,
- "condition" => "greater_than_or_equal_to",
- "condition_value" => 11,
- "labor" => 350
- ],
- [
- "id" => 3,
- "name" => "กระเบื้องธรรมดา ปูธรรมดา A",
- "case" => 0,
- "condition" => "greater_than_or_equal_to",
- "condition_value" => 100,
- "labor" => 320
- ],
- [
- "id" => 4,
- "name" => "งานเดินเมนระบบไฟฟ้า A",
- "case" => 1,
- "condition" => "less_than_or_equal_to",
- "condition_value" => 7,
- "labor" => 1450
- ],
- [
- "id" => 5,
- "name" => "งานเดินเมนระบบไฟฟ้า A",
- "case" => 1,
- "condition" => "greater_than_or_equal_to",
- "condition_value" => 8,
- "labor" => 70
- ],
- ];
- // dd($array);
- $want = 11;
- $sum = 0;
- foreach($array as $value){
- if($value['case'] == 0){ //กรณีที่ 1
- if($value['condition'] == "less_than_or_equal_to"){
- if($want <= $value['condition_value']){
- echo $sum = $value['labor']."\n";
- }
- }
- if($value['condition'] == "greater_than_or_equal_to"){
- if($want >= $value['condition_value']){
- echo $sum = $want * $value['labor']."\n";
- }
- }
- }else{ //กรณีที่ 2
- if($value['condition'] == "less_than_or_equal_to"){
- // $firstValue = $value['condition_value'];
- // $firstLabor = $value['labor'];
- if($want <= $value['condition_value']){
- echo $sum = $value['labor']."\n";
- }
- }
- if($value['condition'] == "greater_than_or_equal_to"){
- $difference = ($want - 7); //หาส่วนต่าง
- if($want >= $value['condition_value']){
- $sum = ($difference * $value['labor']) + 1450;
- echo $sum."\n";
- }
- }
- }
- } //end foreach
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement