function.php 770 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. //数组转对象
  3. use App\Services\Base\ErrorCode;
  4. if(!function_exists('object_array')){
  5. function object_array($array) {
  6. if(is_object($array)) {
  7. $array = (array)$array;
  8. }
  9. if(is_array($array)) {
  10. foreach($array as $key=>$value) {
  11. $array[$key] = object_array($value);
  12. }
  13. }
  14. return $array;
  15. }
  16. }
  17. if(!function_exists('genApiData')){
  18. function genApiData( $code = 200, $message = '', $data = '')
  19. {
  20. if ($code == 200 && empty($message)) {
  21. $message = 'success';
  22. }
  23. $ret = [
  24. 'status' => $code,
  25. 'message' => $message,
  26. 'data' => $data
  27. ];
  28. return json_encode($ret);
  29. }
  30. }