0
    echo 'position: '.$position.'<br/>district: '.$district;
    if($position == 0 && $district == 0){
        $results = DB::table('salaries')
            ->join('districts', 'salary_district', '=', 'district_id')
            ->join('companies', 'salary_company', '=', 'company_id')
            ->join('positions', 'salary_position', '=', 'position_id')
            ->paginate($pages);
       echo '<br/>first';
    } elseif($district == 0 && $position != 0){
        $results = DB::table('salaries')
            ->join('districts', 'salary_district', '=', 'district_id')
            ->join('companies', 'salary_company', '=', 'company_id')
            ->join('positions', 'salary_position', '=', 'position_id')
            ->where('position_name', '=', $position)
            ->paginate($pages);
        echo '<br/>second';
    } else {
        $results = DB::table('salaries')
            ->join('districts', 'salary_district', '=', 'district_id')
            ->join('companies', 'salary_company', '=', 'company_id')
            ->join('positions', 'salary_position', '=', 'position_id')
            ->where('position_name', '=', $position)
            ->where('district_id', '=', $district)
            ->paginate($pages);
        echo '<br/>third';
    }

Output:

position: Contabilista
district: 0
first

How does $position having contabilista give me a true when comparing to 0? What am I missing?

i alarmed alien
  • 9,412
  • 3
  • 27
  • 40
aabreu
  • 337
  • 2
  • 16
  • 1
    Use `$position === 0`. I'm looking around for an existing answer that explains it, but long story short, PHP casts the non-numeric string to an int to compare it, and that cast results in zero. `0 == 0` – Michael Berkowski Oct 05 '14 at 13:43
  • Self-duh, sort of like javascript's value operator and value&type operator? Although the 0 came from a URL, and it technically was a string, so I'd have to be doing '0', I have converted it to an int and all is well. – aabreu Oct 05 '14 at 13:52

0 Answers0