fork download
  1. <?php
  2.  
  3. $obrigatorios = ["order", "preco", "comprador"];
  4.  
  5. $simular_get = ["order" => 13, "preco" => 12060, "comprador" => "Fulano"];
  6.  
  7. if (!array_diff($obrigatorios, array_keys($simular_get))) {
  8. echo "True #1".PHP_EOL;
  9. var_export( $simular_get );
  10. } else {
  11. echo "Error #1";
  12. }
  13.  
  14. echo PHP_EOL . PHP_EOL;
  15.  
  16. $simular_get = ["order" => 13, "bar" => "foo", "preco" => 12060, "comprador" => "Fulano"];
  17.  
  18. if (!array_diff($obrigatorios, array_keys($simular_get))) {
  19. echo "True #2".PHP_EOL;
  20. var_export( $simular_get );
  21. } else {
  22. echo "Error #2";
  23. }
  24.  
  25. echo PHP_EOL . PHP_EOL;
  26. echo PHP_EOL . PHP_EOL;
  27.  
  28. $simular_get = ["order" => 13, "preco" => 12060, "comprador" => "Fulano"];
  29.  
  30. if (!array_diff_assoc($obrigatorios, array_keys($simular_get))) {
  31. echo "True #3".PHP_EOL;
  32. var_export( $simular_get );
  33. } else {
  34. echo "Error #3";
  35. }
  36.  
  37. echo PHP_EOL . PHP_EOL;
  38.  
  39. $simular_get = ["order" => 13, "preco" => 12060, "bar" => "foo", "comprador" => "Fulano"];
  40.  
  41. if (!array_diff_assoc($obrigatorios, array_keys($simular_get))) {
  42. echo "True #4".PHP_EOL;
  43. var_export( $simular_get );
  44. } else {
  45. echo "Error #4";
  46. }
Success #stdin #stdout 0s 82880KB
stdin
Standard input is empty
stdout
True #1
array (
  'order' => 13,
  'preco' => 12060,
  'comprador' => 'Fulano',
)

True #2
array (
  'order' => 13,
  'bar' => 'foo',
  'preco' => 12060,
  'comprador' => 'Fulano',
)



True #3
array (
  'order' => 13,
  'preco' => 12060,
  'comprador' => 'Fulano',
)

Error #4