我已经在我的一个项目上工作了几天,基本上我在这个项目中要做的是比较用户通常在 excel 中执行的 csv 文件,每天晚上在 php 中自动执行。我从 CSV 的介绍数组中获得了信息,但是我无法将它们组合起来以获得每本书的正确信息,因此下面的示例和问题。
我有来自 csv 文件的以下数组(array1),在巫婆中 [5] 键将始终为 0 :
Array
(
[0] => Array
(
[0] => book1
[1] => description1
[2] => category1
[3] => code1
[4] => editor1
[5] => 0
[6] => eur
[7] => out of stoc
)
[1] => Array
(
[0] => book2
[1] => description2
[2] => category2
[3] => code2
[4] => editor2
[5] => 0
[6] => curr2
[7] => out of stoc
)
[2] => Array
(
[0] => book3
[1] => description3
[2] => category3
[3] => code3
[4] => editor3
[5] => 0
[6] => curr3
[7] => out of stoc
)
[3] =>
)
以及来自第二个 csv 文件的另一个数组(array2):
Array
(
[0] => Array
(
[0] => book1
[1] => description1
[2] => category1
[3] => code1
[4] => editor1
[5] => 9
[6] => eur
[7] => out of stoc
)
[1] => Array
(
[0] => book2
[1] => description2
[2] => category2
[3] => code2
[4] => editor2
[5] => 0
[6] => curr2
[7] => out of stoc
)
[2] => Array
(
[0] => book3
[1] => description3
[2] => category3
[3] => code3
[4] => editor3
[5] => 12
[6] => curr3
[7] => in stoc
)
[3] =>
)
和来自另一个csv的array3:
Array
(
[0] => Array
(
[0] => book1
[1] => description1
[2] => category1
[3] => code1
[4] => editor1
[5] => 10
[6] => eur
[7] => in stoc
)
[1] => Array
(
[0] => book2
[1] => description2
[2] => category2
[3] => code2
[4] => editor2
[5] => 0
[6] => curr2
[7] => out of stoc
)
[2] => Array
(
[0] => book3
[1] => description3
[2] => category3
[3] => code3
[4] => editor3
[5] => 0
[6] => curr3
[7] => out of stoc
)
[3] =>
)
我想知道如何返回一个附加数组(array4),其中包含 [5] 键的最小值,但 0 除外,因为对于数组 Ex 中的每个项目,array1 中的 [5] 键始终为 0:
Array
(
[0] => Array
(
[0] => book1
[1] => description1
[2] => category1
[3] => code1
[4] => editor1
[5] => 10 // 9 < 10, but 9 is not in stock so the next value > 0 is 10
[6] => eur
[7] => in stoc
)
[1] => Array
(
[0] => book2
[1] => description2
[2] => category2
[3] => code2
[4] => editor2
[5] => 0 // because this book has 0 price in all arrays, hence the price
[6] => curr2 // is not valid
[7] => out of stoc
)
[2] => Array
(
[0] => book3
[1] => description3
[2] => category3
[3] => code3
[4] => editor3
[5] => 12 // because the only array that contains a valid price is array2
[6] => curr3
[7] => out of stoc
)
[3] =>
)