Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php数组对我来说没用_Php_Arrays_Multidimensional Array - Fatal编程技术网

Php数组对我来说没用

Php数组对我来说没用,php,arrays,multidimensional-array,Php,Arrays,Multidimensional Array,我在txt文件中有以下商店产品的数据: product 1 product 1 product 2 product 2 product 2 product 1 product 1 product 3 product 3 product 3 product 1 product 1 product 3 product 1 好的,人们将产品添加到购物卡中,然后将这些产品插入到一般文本中 要恢复数据,我使用下一个脚本: 感谢您的问候使用下面的代码 <?php $file_data=file("

我在txt文件中有以下商店产品的数据:

product 1
product 1
product 2
product 2
product 2
product 1
product 1
product 3
product 3
product 3
product 1
product 1
product 3
product 1
好的,人们将产品添加到购物卡中,然后将这些产品插入到一般文本中

要恢复数据,我使用下一个脚本:

感谢您的问候使用下面的代码

<?php

$file_data=file("output_rrr.txt");


for ($i=0;$i<sizeof($file_data);$i++)
{


/// Create array of groups


$global_products[]=$file_data[$i];

}

/// Now i want get the products and the number in each case for example of the product 1 i have 6 for the product 2 i have 3 and for the product 3 i have 4 , ok for get this i can use thi function 




$prr=array_count_values($global_products);
foreach($prr as $key=>$value)
{
    echo trim($key).": ".$value."<br/>";

}




?>

循环遍历数组$prr并以您喜欢的方式打印每个条目。我猜op想要计算文件中每个产品的眼病数。您能告诉我如何做到这一点吗,您能举个例子吗,谢谢!!!
Product 1 (6)
Product 2 (3)
Product 3 (4)
<?php

$file_data=file("output_rrr.txt");


for ($i=0;$i<sizeof($file_data);$i++)
{


/// Create array of groups


$global_products[]=$file_data[$i];

}

/// Now i want get the products and the number in each case for example of the product 1 i have 6 for the product 2 i have 3 and for the product 3 i have 4 , ok for get this i can use thi function 




$prr=array_count_values($global_products);
foreach($prr as $key=>$value)
{
    echo trim($key).": ".$value."<br/>";

}




?>