c4n10 Posted March 22, 2013 Share Posted March 22, 2013 Hello all, I am working on a site which is returning "Warning: Invalid argument supplied for foreach()" The function that is returning the warning is: function currentworkers() { $currentworkers = 0; if (!($currentworkers = getCache("pool_workers"))) { $uwa = $this->workerhashrates(); foreach ($uwa as $key => $value) { if ($value > 0) $currentworkers += 1; $ } setCache("pool_workers", $currentworkers, 1800); } return $currentworkers; } Any help is greatly appreciated, thanks!!! Quote Link to comment https://forums.phpfreaks.com/topic/275991-invalid-argument-supplied-for-foreach/ Share on other sites More sharing options...
Barand Posted March 22, 2013 Share Posted March 22, 2013 It looks as though $this->workerhashrates() is not returning an array Quote Link to comment https://forums.phpfreaks.com/topic/275991-invalid-argument-supplied-for-foreach/#findComment-1420232 Share on other sites More sharing options...
c4n10 Posted March 22, 2013 Author Share Posted March 22, 2013 It looks as though $this->workerhashrates() is not returning an array You are absolutely correct, turns out the backend code we are using hasn't been writing to the db so there has been no info to retrieve so it is returning an empty array, thank you for the help! Quote Link to comment https://forums.phpfreaks.com/topic/275991-invalid-argument-supplied-for-foreach/#findComment-1420237 Share on other sites More sharing options...
davidannis Posted March 22, 2013 Share Posted March 22, 2013 You can verify what Barand said is true with: $testme= gettype($uwa) echo $testme; if ($testme=='array') { print_r($uwa); } Quote Link to comment https://forums.phpfreaks.com/topic/275991-invalid-argument-supplied-for-foreach/#findComment-1420238 Share on other sites More sharing options...
Barand Posted March 22, 2013 Share Posted March 22, 2013 or simply var_dump($uwa); Quote Link to comment https://forums.phpfreaks.com/topic/275991-invalid-argument-supplied-for-foreach/#findComment-1420241 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.