There is such code:

$_POST['crm_token'] = '4ab822cb-ecd3-4138-aceb-51c2ac13db7e'; $_POST['cmd'] = 'contact'; $_POST['phone'] = 'phone'; $_POST['callid'] = 'callid'; function check($required, $array) { foreach ($required as $key) { if (!array_key_exists($key, $array)) return false; } } $required = array('phone', 'crm_token', 'callid'); if (!$this->check($required, $_POST)) { return http_response_code(400); } 

As a result, returns 400. Why? It should not.

  • And you have not forgotten to return true, if all is well? - Mikhail Vaysman
  • But is it returned by default, or not? - Timur Musharapov
  • Put, but the result was the same. - Timur Musharapov
  • one
    If the return is omitted, it will return null. And this is regarded as false. Show how you added the return in question. - Mikhail Vaysman
  • one
    at the end of the method, function check($required, $array) { foreach ($required as $key) { if (!array_key_exists($key, $array)) return false; } return true; } function check($required, $array) { foreach ($required as $key) { if (!array_key_exists($key, $array)) return false; } return true; } function check($required, $array) { foreach ($required as $key) { if (!array_key_exists($key, $array)) return false; } return true; } - Alexey Shimansky

1 answer 1

Your check function should return true at least at the end! Here is an example and everything is OK

  $arr['crm_token'] = '4ab822cb-ecd3-4138-aceb-51c2ac13db7e'; $arr['cmd'] = 'contact'; $arr['phone'] = 'phone'; $arr['callid'] = 'callid'; function check($required, $array) { foreach ($required as $key) { if (!array_key_exists($key, $array)) return false; } return true; } $required = array('phone', 'crm_token', 'callid'); if (!check($required, $arr)) { echo 'false'; } 
  • You also wrote, you and there in the check function do not have return true - Orange_shadow
  • And, everything, was not kept simply. Thank you) - Timur Musharapov