The knowledge points that the PHP teacher didn't teach you.

Source: Internet
Author: User
Tags php script

The alternative is a surprise.

When we read some of the source code, we find that there is an alternative way of writing, such as

//Unusual wordingif(false = = $result) //Normal wordingif($result = = false)

In fact, this is a very clever way of writing, it can be to a large extent to eliminate the serious error caused by hand. If we were to make a normal method of==Mistakenly written=Soif($result = false)will be constant return true, resulting in the actual operation of an unknown bug, if the use of the exception of the wording of the hand into the wrongif(false = $false), the editor throws an error and we can find and fix the problem in time.

Do not have a blank line before ' <?php ', php script end '?> ' try to omit

If there is a file in?>After there is a blank line, then you are usingsession_start()When you wait for a method, a warning is returnedheaders already sent by xxx, this is becausesession_start()No output is required before use. Similarly<?phpThe same problem exists in the previous empty line.

When strings and numbers are together, be carefulVar_dump(A.0); //returns error, syntax error solution is relatively simple, as long as the . connecting left and right with spaces will prevent grammatical errors. var_dump (' abc ' = = 0); //Output True var_dump (' 1abc ' = = 0); //Output false

The output of true in this example is not a surprise to you, in fact, in PHP when the string and the number is compared, the string will be cast to int, the conversion rule is如果字符串是数字开头,那么取开头数字作为转换结果,如果开头不是数字那么就为0

The arithmetic of string, you can't provokefor ($i = ' a '; $i <= ' z '; + +$i) { echo "$i"; }do you think it will output from A to Z? Then you're wrong, you're blind. The output is as follows:.

A b c d e F g h i j k l m n o p q R S t u v w x y z aa ab AC ad AE af ag ah AI aj Ak al am an AO ap aq ar as at au av aw A x ay az ba bb BC BD is BF BG BH BI BJ BK bl bm bn bo BP bq br bs BT BU BV bw BX by BZ CA CB CC CD CE CF CG ch CI CJ CK cl CM CN CO CP CQ CR CS CT CU CV cw cx cy CZ da DB DC dd de DF dg DH di dj DK dl DM DN Do DP dq Dr ds dt du dv DW dx dy DZ ea EB ec ed ee ef eg eh el ej ek el em en eo ep eq er es et eu ev ew EX EY EZ FA FB FC FD FE FF FG fh FI FJ FK FL FM fn FO f P FQ fr fs ft fu FV FW fx FY FZ GA GB GC GD GE GF GG GH gi GJ GK GL GM gn go GP GQ gr GS gt gu gv GW gx gy GZ ha HB HC HD He hf Hg HH Hi HJ HK HL HM hn HO HP HQ HR HS HT hu HV HW HX hy Hz IA IB IC ID ie if IG ih ii ij ik il im in io IP iq ir is It IU IV iw IX iy iz ja jb JC JD JE jf jg JH ji JJ JK JL JM Jn Jo JP JQ Jr JS JT Ju JV jw jx jy jz ka kb kc kd ke kf kg k H ki kj kk kl miles kn ko kp kq kr ks kt ku KV KW kx ky KZ la lb LC ld le LF lg LH Li LJ lk ll LM LN LO LP LQ LR LS lt lu lv LW LX ly LZ MA MB MC MDMe mf mg MH mi MJ mk ml mm MN Mo MP MQ Mr Ms Mt MU mv MW mx my mz na nb nc nd ne nf ng nh ni nj nk nl nm NN no NP NQ nr NS NT Nu NV NW NX NY NZ OA ob oc od oe of og oh oi oj ok ol om on oo op oq or os ot ou ov ow ox oy oz PA pb pc PD PE PF PG P H Pi PJ Pk pl pm PN PO pp PQ PR PS pt PU PV pw px py pz QA QB QC QD QE QF QG QH qi qj qk ql QM qn qo qp qq qr Qs qt qu QV QW qx qy QZ ra RB RC Rd RE RF RG RH RI RJ RK RL RM RN RO RP RQ rr rs rt ru RV rw rx ry rz sa sb sc sd se SF sg sh si sj SK SL SM SN So sp sq SRS SS St Su SV SW sx sy SZ TA TB tc TD te TF tg th ti TJ tk tl TM TN to TP TQ TR ts TT tu TV tw tx ty t Z UA UB UC UD UE uf UG UH UI UJ UK ul um un uo up UQ ur us ut uu uv uw ux uy uz va vb vc VD ve VF VG VH VI VJ VK VL VM VN VO VP VQ VR vs VT vu VV VW VX VY VZ wa WB WC WD WE WF WG WH WI WJ wk wl wm wn wo wp wq WR ws WT Wu WV WW WX WY wz XA XB XC XD XE XF xg XH XI xj xk XL xm xn xo xp XQ XR XS xt Xu XV xw xx xy XZ ya yb yc yd ye yf yg yh yi yj yk yl ym yn yo yp yq y R ys yt yu yv yw yx yy yZ

Always be careful of the loss of precision$f = 0.58; echo intval($f * ); //Output sprintf("%.2f",$f * ); //Output 58.00

The problem of loss of precision is there in other languages, but more attention is needed in the weakly typed language of PHP.

In fact, the above mentioned problems in the PHP manual has been referred to, manual turn times code, such as God, a certain amount of careful experience, you will be able to develop the road pits all the way forward.

The knowledge points that the PHP teacher didn't teach you

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.