Convert boolean to integer value php Convert boolean to integer value php php php

Convert boolean to integer value php


Just add a "+" before your variable like this :

$myBool = true; var_dump(+$myBool);ouputs: int(1);


// cast to Integerecho (int)true;         // 1echo (int)false;        // 0// get the integer value from argumentecho intval(true);      // 1echo intval(false);     // 0// simply echoing true returns 1echo true;              // 1// you can even add those valuesecho true + true;       // 2