<?php namespace app; class foo { public array $informationArray; /** * @param array $columns * @param array $data * @param string $title * @return string|null */ public function createJsonArray(array $columns, array $data, string $title): ?string { if ($columns && $data) { $this->informationArray = [ "meta" => [ "title" => $title, "columns" => $columns, "perPage" => 10, "currentPage" => 1, "params" => [ "class" => "table table-bordered", "border" => "1" ] ], "data" => $data ]; return $this->toJson($this->informationArray); } return null; } /** * @param array $infArr * @return string|null */ protected function toJson(array $infArr): ?string { if ($infArr) return json_encode($infArr, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); return null; } }