php - Warning: Invalid argument supplied for foreach() despite everything looking fine -
I have an array that is being sent to a forecaster and even if I used foreach hundreds of times ago , ---- Since apparently this works, here the entire callstack is This is not the right answer, I just want to know that this error Will press:
switch (search by $) {case 0: // name print_r ($ data); Forex currency ($ data as $ key => $ i) {if ($ key% 2 == 0 & amp; $ i == $ search) {$ success = TRUE; $ Matches [] = array ('name' = & gt; $ i, 'value' = & gt; $ data [$ key + 1]); } } break; For example (a real example)
print_r prints a common array:
Array ([0] = & Gt; Username [1] = & gt; 4567 [2] = & gt; Password [3] => 4567 [4] => Name [5] => 4567 [6] = > Age [7] = & gt; 4567 [8] => Country [9] => 4567 [10] => Type [11] => Register) < / Pre>
& lt; ------ : ----
/// Managed with the stack marked with /// $ ("Form # Register") Submit Please. (Function () {event.preventDefault (); $ .post ("php / proc.php", {'command': 'registerUser', 'data': $ (this). Serialize ()}, function (data) {// & lt; ---- Basic call console.log (data);}); Returned;}); // proc.php // echo json_encode ($ MainLib- & gt; register user ($ db, $ data)); // & lt; --------- # 1 class MainLib {public function register user ($ db, $ data) {$ pword = $ this- & gt; Keyword ($ db, $ result1 [0] ['value'], $ result 2 [0] ['value'], 'register'); // & lt; ---------------- # 2} public function is keyword ($ db, $ data) {$ uname = $ this- & gt; SearchData (0, 'Username', $ data); // & lt; ----------- # 3 $ pword = $ this- & gt; Search data (0, 'password', $ data); $ Type = $ this- & gt; Search data (0, 'type', $ data); Switch ($ type) {case 'register': $ salt = uniqid (rand (0, 99 99 99 99, TRUE); $ Db- & gt; Query ("UPDATE` user 'set` salt` ='. $ Salt. '' 'Username' = '". $ Uname."' '"); Echo "UPDATE` user 'set` salt` =' ". $ Salt "'WHERE' user name` = '". $ Only "'"; break; $ Result = $ db- & gt; Query ("Select * from user 'where' username '='". $ Uname. "'"); While ($ line = $ result-> fetch_assoc ()) {$ salt = $ line ['salt']; }} $ Salt = base_convert ($ salt, 26, 10); $ Pword = base_convert ($ pword, 26, 10); $ New_pword = $ pword * $ salt; $ New_pword = base_convert ($ new_word, 10, 17); $ Pword = hash ('sha512', $ new_pword); $ Pword return; } Public Function SearchData (search by $, $ search, $ data) {$ success = FALSE; Switch (search by $) {case 0: // name print_r ($ data); Foreign currency ($ data as $$ data => $ i) {// < --------- Error if ($ key% 2 == 0 & amp; $ i == $ for search) {$ success = true; $ Matches [] = array ('name' = & gt; $ i, 'value' = & gt; $ data [$ key + 1]); } } break; Case 1: // Value Project ($ data as $ $ => $ i) {If ($ Key% 2 == 0 & amp; amp; $ data [$ of + 1] == $ To search) {$ success = true; $ Matches [] = array ('name' = & gt; $ i, 'value' = & gt; $ data [$ key + 1]); } } break; } If ($ success) returns $ matches; return false; }}
switch (search by $) {case 0: // if name is (is_array ($ data)) {// - & gt; Add print_r to this verification ($ data); Forex currency ($ data as $ key => $ i) {if ($ key% 2 == 0 & amp; $ i == $ search) {$ success = TRUE; $ Matches [] = array ('name' = & gt; $ i, 'value' = & gt; $ data [$ key + 1]); }}} And die ('invalid hey!'); } break; } Try adding the
is_array position if it can still print the value of
$ data and your The script is able to continue.
Comments
Post a Comment