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,我有两个数组 //each array contains 8 values $ids = Array(1441, 1313, 1123, 1316, 1313, 1313, 1123, 1567); //each id has a value in $data array $data = Array(2, 3, 8, 4, 5, 4, 2, 9); //here is my problem: $max_data = array_product($data); //but not all

我有两个数组

//each array contains 8 values
$ids = Array(1441, 1313, 1123, 1316, 1313, 1313, 1123, 1567);
//each id has a value in $data array
$data = Array(2, 3, 8, 4, 5, 4, 2, 9);


//here is my problem: 

$max_data = array_product($data); //but not all values from $data only these:
$ids = [1441,1123,1316,1313,1567]; //these are the ids with highest data.
echo $max_data; //result must be 2880 (2 * 8 * 4 * 5 * 9)
$min_data = array_product($data); //and now
$ids = [1441,1313,1316,1123,1567]; //these are the ids with lowest data.
echo $max_data; //result must be 432 (2 * 3 * 4 * 2 * 9)
我希望,我能够解释我的问题

谢谢


解决了它。

我已经做了一个函数来获取最大值和最小值。我想得到更好的答案,谢谢


我不确定我是否理解正确,但关联数组不是您需要的吗

$foo = Array(2 => 1441, 3 => 1313 .... )

$foo = Array(2 => 1441, 3 => 1313 .... )