fork download
  1. <?php
  2.  
  3. function test($obj) {
  4. $checks = [
  5. ['status', 1, 0],
  6. ['id', 2, 2],
  7. ['user', 4, 3],
  8. ['auth', true, 4],
  9. ['map', 'russia', 5],
  10. ['name', 'john', 6],
  11. ];
  12.  
  13. foreach ($checks as $check) {
  14. if ($obj[$check[0]] != $check[1]) {
  15. return $check[2];
  16. }
  17. }
  18.  
  19. return 1;
  20. }
  21.  
  22. echo test([status => 1, id => 2, user => 7]);
Success #stdin #stdout #stderr 0.02s 24376KB
stdin
Standard input is empty
stdout
3
stderr
PHP Warning:  Use of undefined constant status - assumed 'status' (this will throw an Error in a future version of PHP) in /home/gpekUc/prog.php on line 22
PHP Warning:  Use of undefined constant id - assumed 'id' (this will throw an Error in a future version of PHP) in /home/gpekUc/prog.php on line 22
PHP Warning:  Use of undefined constant user - assumed 'user' (this will throw an Error in a future version of PHP) in /home/gpekUc/prog.php on line 22