logs archiveIRC Archive / Freenode / #php / 2015 / September / 3 / 15
kkspy
caffinated: The thing is, Russian ruble sank below any reasonable depths and I had have to begin to work on foreign companies :)
Logicgate
you could also use printf...
mewm
kkspy, sure.
kkspy
mewm: I've sent you a link in PM ;-)
Logicgate
tamuren, this is also where I'd make a small function to handle label creating perhaps.
Glaisher
Is there a more performant way to do in_array for large arrays?
large = very very large
Naktibalda
Glaisher: no
Logicgate
Glaisher, associative?
kkspy
Glaisher: array_flip() and then isset
         

Logicgate
Or flat
biberu
Glaisher: is the array sorted?
Glaisher
no
Logicgate
I'd do isset if it's associative
kkspy
Glaisher: if you need more than one in_array(), you can array_flip() and then isset()
Glaisher
kkspy: wouldn't running array_flip again slow down things?
alreece45
cd #phpspec
kkspy
in_array() is essentially a full-scan whereas isset() is using B-tree
alreece45
Guess that's not a command on irc..
kkspy
Glaisher: it will, use array_flip only if you can use in_array() at least twice on the same array without flipping twice.
Glaisher: why don't you form your array in an associative way from the get-go?
Glaisher
because the array is like this array( '1', '5', '3', '7' )
It's a huge array of user ids. Then I'm trying to check whether an id is present or not
kkspy
Just one time? Use in_array()
Glaisher
Is there a better way to do it?
Logicgate
Glaisher, does this function get called frequently?
kkspy
But there's a little trick. Use in_array($id, $array, true)
Glaisher
yes,
kkspy
You don't need no loose comparison.
DissidentRage
^
Glaisher
That will make things a lot faster when compared to non-strict?
biberu
Glaisher: why do you have such a huge, unsorted array to begin with? can you avoid it?
         

Glaisher
trying to do less db queries.. maybe it's better if I just do it directly from the queries instead of php?
kkspy
Glaisher: I've not benchmarked it, but it will definitely be faster.
Glaisher: use Mongodb ;-))
Glaisher
ok, I think I'll just let sql do it
Sammitch
DBMSes are VERY GOOD at dealing with large datasets for *some* reason
Glaisher
I can't decide on these things.. ;)
kkspy
Glaisher: Or, which is even better, use Redis :)
biberu
Glaisher: almost certainly, but make sure you are using indexes and reusing the same statement handle whenever possible
DissidentRage
I'm gonna guess no, but has anyone here made a "Twitter card"?
Glaisher
biberu: yeah, sure
laszlof
DissidentRage: you mean that annoying spam I get from twitter every few weeks
DissidentRage
laszlof: I have no idea, I only barely used it, mainly to read doge posts
:P
djlee
Anyone a wiz with gettext. If i put my romanian characters from my po file into the document and save, its fine. If i put the romaina chars inside _('xxx') it works fine. However if i leave the english in _() function, and let gettext translate from the po files, i get black diamonds (utf8 replacement char)
diamonds
what
did you say
laszlof
eh
black diamond
djlee
its as if gettext is looking up the translation and not returning in the correct charset (which it can't be as that would be silly, but thats what it appears like)
https://en.wikipedia.org/wiki/Specials_(Unicode_block)
black diamond aka replacement char
mewm
djlee do you make sure the po files are saved as utf8?
if you open it in poedit, it will warn you if the text file charset in incorrect
djlee
mewm: yep, po file is (text/x-po; charset=utf-8), mo file is (application/octet-stream; charset=binary)
mewm
djlee, is the problem that the fallback value (in this case english?) is retuned in incorrect encoding, or is it all english translation values that are incorrect?
djlee
po was supplied by the translator, and i can open it up (i copied and pasted a line out to test it, like i said if i save the string to the php file it outputs fine, but looking up the translation via gettext causes the bad char symbol)
mewm
fallback value ie. the actualy key
actual*
djlee
mewm: default language is english, and english is used in the _('xxx') function as the key. Im using the po file to trnalste my keys to romanian
mewm
yes I see... Are you seeing the symbols via a browser?
MarkyC
I have an array like [ 0 => { id: 123, ... }, 1 => { id: 456; ...}]. Is there a one-liner to get an array of only the id's?
NoiseEee
if there was, would that be better than a 2/3/5/10 liner?
and why?
mewm
MarkyC, isn't that mixed php and js syntax?
NoiseEee
and yes ^^
MarkyC
I could do $ids = []; foreach ($arr as $v) { $ids[] = $v['id'] } but I figured there would be a shorthand for that
mewm
MarkyC use array_map
$ids = array_map(function($item) { return $v['od
caffinated
MarkyC: array_column()
mewm
$ids = array_map(function($item) { return $v['id'] }, $array):
MarkyC
caffinated: I knew it existed! Thank you
caffinated
it's newer, make sure your php version supports it first
djlee
mewm: yep, the symbols are showing up in browser. If i cat the po file in terminal, characters output fine, likewise if i paste the romanian into the the php file directly (both as echo 'roman' and echo _('roman')) it outputs fine. It only outputs the symbols when i run an english key through gettext expecting romanian back
NoiseEee
beauty
hrusti
I have results table http://sqlfiddle.com/#!9/60801/1 and I have to create leaderboard. I have to select user that is before and after user_id=someId by the number of points and its position in general. Except if user is first I have to select first 3 and same for last 3. I am using mysql. Should I do this in php or query?
mewm
djlee, you've checked you've set the charset in the html correctly, and then in fact, the romanian po file is in a wrong charset :P ?
tamuren
Hey guys I have two php files in the same directory. They both call on a variable $CFG. file A can reference it successfully but file B says undefined variable
Neither declare the variable
How do I reference CFG in both php files?
caffinated
tamuren: it depends on the scope of the definition, and when the files are included.
tamuren: basically, without seeing the code there's no way to arrive at a difinitive answer
tamuren
bummer
djlee
mewm: yep charset set to utf8 in php.ini, header(), <meta> (everywhere i could possibly throw it to be sure). Like is say, it does output correctly when i enter the characters into the file and save it, and the po file characters output fine when i open the po file. it is literally only breaking when i run an english key through gettext... really has me confumbled. Might be one to tackle tomorrow with a fresh head
tamuren
If one file could reference it, might we assume that file must have a include or require declaration?
mewm
djlee, we use gettext with english keys in 6 different languages and I've encountered quite a few bugs with it. We even had a version of PHP, making all languages literally break if it weren't Israel Hebrew and had to recompile php to get it work again. I've never experienced your kind of problem though.
djlee, good luck tomorrow though x)
codydh
Hello! I'm using League\Csv\Reader's fetchAssoc function to read in a CSV file as an associative array (specifically $data = $reader->fethAssoc(['username', 'usedKB']);)... once I've done that, and I know that's working correctly, how do I return the UsedKB for a particular Username?
caffinated
tamuren: if file B can't get at $CFG then it's either a definition or a scope problem.
it can't really be anything else
tamuren
caffinated: I see
whirledPress
can someone help me to grab the "body" element from about 300 html files and combine them into one html output file? I have been googling, but not finding what I want
caffinated
so: 1) the variable is not defined at that point in the execution, 2) the variable is in the wrong scope (you're trying to use it in a function or method when it's defined globally or vice versa) or 3) it's defined in an an included file which has not been included yet.
djlee
mewm: honestly my first time with gettext so it's taken a while to start understanding it. en_US and en_GB did my head in for a few hours yesterday until i realised i could just take the language portion and drop the region to save having regional variants to support where not really required
caffinated
or 4) it never gets defined.
djlee
mewm: but yeah, gonna shoot off home and see if alcohol will help solve the problem. if not, tomorrow will be fun!
tamuren
caffinated: That scope bit sounds on point
$CFG is a global variable used by moodle. And I reference it inside a function defined in functions.php
caffinated
« prev 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 next »