mercredi 24 février 2021

How to convert string to boolean multiple condition in php

How to convert string to conditional boolean

example string with boolean condition.

$condition1 = 'false || ( true && false)'; // should return false
$condition2 = 'false || true';  // should return true
$condition3 = 'true && false';  // should return false
$condition4 = 'true && (true || false);  // should return true

I tried these codes but not working..

$result =  (boolean) $condition1;
$result = filter_var($condition1, FILTER_VALIDATE_BOOLEAN);
$result = settype($condition1, 'boolean');

is there a way to convert it?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire