  # jonnyenglish89

Members

14

## Community Reputation

0 Neutral

• Rank
Member
1. Thanks for the translation I could do with some help with 5b. I can remove the first instance of of the selected letter within the function selectNextNumber with unset(\$bestOrder[\$x]) and return the updated \$bestOrder array and \$numberToPick is that a good way to do it or would you recommend somethingelse?
2. Hi guys, I’d appreciate a little guidance but I’m gonna struggle to explain what the problem is first… so apologies in advance. \$drawOrder is an array of 1 to 10 letters that are drawn at random Array (  => C  => F  => D  => J  => B  => H  => I  => G  => E  => A ) \$bestOrder contains the same values as \$drawOrder but the letters are given a priority. Array (  => A  => B  => C  => D  => E  => F  => G  => H  => I  => J ) \$bestPossibleOrder – I want this to contain the closest order possible to \$bestOrder based on the draw order and 3 letter draw limit Array (  => C  => D  => B  => F  => H  => G  => E  => A  => I  => J ) \$availableLetters contains 3 letters that are drawn according to \$drawOrder. Array (  => C  => F  => D ) add “ => C” to \$bestPossibleOrder array remove “ => C” from the \$bestOrder array because the letters are not always unique add “ => J “ to \$availableLetters because it is next in the draw order. Array (  => F  => D  => J ) add “ => D” to my \$bestPossibleOrder array remove “ => D” from the \$bestOrder array because the letters are not always unique add “ => B“ to \$availableLetters because it is next in the draw order. Array (  => F  => J  => B ) Repeat the process until all letters are in the \$bestPossibleOrder array Array (  => C  => D  => B  => F  => H  => G  => E  => A  => I  => J ) I’ve attached what I’ve written so far but I’m not sure if it’s a good approach <?php \$BR = "<br />"; echo "best order:" . \$BR; \$bestOrder = array("A","B","C","D","E","F","G","H","I","J"); print ("<pre>" . print_r(\$bestOrder, true) . "</pre>"); echo "draw order:" . \$BR; \$drawOrder = shuffle_assoc(\$bestOrder); \$drawOrder = array_combine(range(101,(count(\$bestOrder)+100)),\$drawOrder);// \$drawOrder array keys have to start from 101 print ("<pre>" . print_r(\$drawOrder, true) . "</pre>"); echo "available Letters (FIRST DRAW):" . \$BR; \$availableLetters = array_slice(\$drawOrder, 0, 3,true); print ("<pre>" . print_r(\$availableLetters, true) . "</pre>"); \$numberToPick = selectNextNumber(\$bestOrder,\$availableLetters); echo "The key with the closest letter to best order is [" . \$numberToPick . "]"; function selectNextNumber(\$bestOrder,\$availableLetters){ for (\$x = 0; \$x <= count(\$bestOrder); \$x++){ \$numberToPick = array_search(\$bestOrder[\$x], \$availableLetters); if (\$numberToPick !== false) { //unset(\$bestOrder[\$x]); //print ("<pre>" . print_r(\$bestOrder, true) . "</pre>"); return \$numberToPick; } } } function shuffle_assoc(\$list) { if (!is_array(\$list)) return \$list; \$keys = array_keys(\$list); shuffle(\$keys); \$random = array(); foreach (\$keys as \$key) { \$random[\$key] = \$list[\$key]; } return \$random; }
3. thank you very much for the help guys! Unfortunately, I’m unable to share the actual code ☹ but you’ve helped me nonetheless
4. Thanks, but the above code is not the code I am using – I wrote that as a simple example of my problem. Taking away the class would mean changing a lot of code
5. Hey guys, How can I access the \$currentAccount and \$numberOfAccounts variables from the construct function and use them in the updateDB function without making them global variables? <?php class Client { public function __construct(\$start = []) { ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); \$sql = mysqli_connect('localhost', 'root', '', 'test'); \$query = "SELECT * FROM users;"; \$ret = mysqli_fetch_all(mysqli_query(\$sql, \$query) , MYSQLI_ASSOC); \$this->print(count(\$ret) . ' Accounts Loaded!'); \$numberOfAccounts = (count(\$ret)); foreach(\$ret as \$k => \$v) { \$start = []; \$start['name'] = \$v['name']; \$start['password'] = \$v['password']; \$currentAccount = 1; \$this->print("processing account number {\$currentAccount} of {\$numberOfAccounts} ..."); \$currentAccount++; \$this->start = \$start; \$this->handshake(\$start); } } public function handshake(\$start) { // makes a connection to an api with the \$start array as parameters and returns \$account_info \$this->updateDB(\$account_info); } public function updateDB(\$account_info) { \$this->print("processed account number {\$currentAccount} of {\$numberOfAccounts} ..."); } public function print (\$str) { print ('[' . date('H:i:s', time()) . '] ' . \$str . PHP_EOL); } }
6. Hey guys how can i use php to turn a string like this: “A, B#2, C#2, D#3, E” Into an array like this: Array (  => A  => B  => B  => C  => C  => D  => D  => D => E ) I can get the letter and count into an array like this with the help of regex: Array ( [A] => 1 => 2 [C] => 2 [D] => 3 [D]=> 1 ) But I have no idea how I would get the result I desire – any help with this part would be greatly appreciated
7. Hey, I’m considering hiring someone to create an app that will act as an intermediary between tasks sent from a vps to a program on my PC which will return the results to the vps. What should I be searching for when researching the pros and con of something like this? Ps, the tasks are very CPU intensive else I wouldn’t consider using my PC.
8. where's the best hint button?
9. nevermind... \$com_array = array_keys(\$main); \$com_id = \$commander_array; \$dom_array = array_keys(\$main); \$dom_id = \$dominion_array; \$cards = json_encode(\$main); this does the trick.
10. ok, I'm still stuck... I've tried this: foreach(\$main as \$key => \$value) { \$t[] = array_keys(\$value); } \$com_id = json_encode(\$t); =  \$dom_id = json_encode(\$t); =  when I do a var_dump it says it's a string: string(7) ""what am I doing wrong?
11. Hey guys, I needed to covert the \$main array in to a string so I used json_encode to do it but now I’m unsure how to get just the key values for \$main and \$main – can anyone help? main array: Array (  => Array (  => 1 )  => Array (  => 1 )  => Array (  => 1  => 1  => 1  => 1 ) ) current code and output: \$com_id = json_encode(\$main); = {"25256":1} \$dom_id = json_encode(\$main); = {"50005":1} \$car_id = json_encode(\$main); = {"301":1,"2318":1,"13403":1,"49489":1} Desired output: \$com_id = {"25256"} \$dom_id = {"50005"} \$car_id = {"301":1,"2318":1,"13403":1,"49489":1}