php - Whats the difference between ? : and || -



php - Whats the difference between ? : and || -

what difference there between using ?: conditional operator , || logical or.

i finding code works with:

$screenpixelratio = !empty($_cookie['screenpixelratio']) || $_cookie['screenpixelratio'] || $fallback_pixelratio;

but not:

$screenpixelratio = !empty($_cookie['screenpixelratio']) ? $_cookie['screenpixelratio'] : $fallback_pixelratio;

could please explain why work one, not other.

|| binary operators operators deal 2 arguments

as says check first if true not gonna check farther else check farther

?: ternary operator operator takes 3 arguments. arguments , result can of different types.

expression1 ? expression2 : expression3;

php

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -