$arr = [
["name" => "Austin"],
["name" => "Nashville"],
["name" => "Foldo"],
["name" => "Femosss"]
];
function arrayFilterFirstChar(array $arr, string $chr): array
{
return array_values(array_filter($arr, fn($val) => $val['name'][0] == $chr));
}
var_dump(arrayFilterFirstChar($arr, 'F'));
function arraySearchSubkey(array $array, string $needle): array
{
return array_filter(
$array,
function($key) use($needle) {
return strpos($key, $needle) !== false;
},
ARRAY_FILTER_USE_KEY
);
}
function arraySearchSubkey(array $array, string $needle): array
{
return array_filter($array, fn($key) => strpos($key, $needle) !== false, ARRAY_FILTER_USE_KEY);
}
$json = '{
"result": {
"Random ItemName": [
{
"user": "user1",
"time_upd": "2020-12-09 12:25:03"
}, {
"user": "user2",
"time_upd": "2020-12-09 12:25:03"
}, {
"user": "user3",
"time_upd": "2020-12-09 12:25:03"
}
]
}
}';
$data = json_decode($json, true);
$i = 0; // меняется в цикле
$user_name = $data['result']['Random ItemName'][$i]['user'];
$time_upd = $data['result']['Random ItemName'][$i]['time_upd'];
$user_name = $data['result'][array_key_first($data['result'])][$i]['user'];
$time_upd = $data['result'][array_key_first($data['result'])][$i]['time_upd'];
foreach ($data['result'] as $arrayKey => $arrayValue) {
foreach ($arrayValue as $arraySubvalue) {
$user_name = $arraySubvalue['user'];
$time_upd = $arraySubvalue['time_upd'];
// …
}
}
http_response_code(404);
exit;
header('Location: …', true, 301);
exit;
header('Location: …', true, 307);
exit;
if ($fh = fopen('/public/vag102020.csv', 'r')) {
while (($csvStr = fgetcsv($fh, 1024, ';')) !== false) {
$csvArr[] = $csvStr;
}
}
$weight = $line[5] ?? 0;
uasort(
$array,
fn($item1, $item2) => ($item1['count'] ?? 0) <=> ($item2['count'] ?? 0)
);
$dataIn = 'Laldldlldlsdls.... Ends Jul 2, 2021';
$dataOut = preg_replace_callback(
'/Ends (.+)/',
fn($matches) => date('F d, Y', strtotime($matches[1])),
$dataIn
);
и теперь php страница возвращает это:
[{"reportId":"1","title":"\u041f\u0435\u0440\u0432\u044b\u0439 \u043e\u0442\u0447\u0435\u0442"}]
json_encode($report, JSON_UNESCAPED_UNICODE)
, то на выходе будет читаемый тест.echo $report['title'];