$x = array(
"name" => "Сулаймон",
"custom" => array(
array(
"name" => "country",
"content" => "Узбекистан",
),
array(
"name" => "last_date",
"content" => "2015-09-15",
),
),
);
echo json_encode($x);
// {"name":"\u0421\u0443\u043b\u0430\u0439\u043c\u043e\u043d","custom":[{"name":"country","content":"\u0423\u0437\u0431\u0435\u043a\u0438\u0441\u0442\u0430\u043d"},{"name":"last_date","content":"2015-09-15"}]}
Function array dereferencing has been added, e.g. foo()[0].
function find_shortest_sentence($text)
{
$sentences = preg_split('/[.!?]\s*/', $text, -1, PREG_SPLIT_NO_EMPTY);
// передали некорректный текст
if (!isset($sentences[0])) {
throw new InvalidArgumentException('Text must contain at least one sentence.');
}
$min = array_shift($sentences);
foreach ($sentences as $sentence) {
if (mb_strlen($sentence) < mb_strlen($min)) {
$min = $sentence;
}
}
return $min;
}
var_dump(
find_shortest_sentence('Первое предложение. Второе предложение. Тр предл.'),
find_shortest_sentence('Первое предложение. Второе предложение. Тр предл')
);
// string(15) "Тр предл"
// string(15) "Тр предл"