从Array PHP获取50个记录



我有一个json文件,我将其转换为数组,然后尝试从数组中获取50个元素。

,但由于某种原因,我的代码不起作用,它抛出212个元素,而不是50

请参阅下面的代码:

$json_file = file_get_contents("/directory/jsonfile.json");
$json_data = json_decode($json_file, true);
$json_data = array_slice((array)$json_data, 0, 50);
print_r (array_count_values($json_data)); // this still showing 212 results

count()返回int array_count_values()返回数组。

看来您需要count()才能获得数组元素的数量。

php:数组计数值

php:count

最新更新