私は数日間自分のプロジェクトに取り組んでいますが、基本的にこのプロジェクトでやろうとしていることは、ユーザーが通常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] =>
)
および 2 番目の 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] =>
)
[5] キーの最小値を持つ追加の配列 (array4) を返す方法を知りたいのですが、array1 の [5] キーは配列内の各項目に対して常に 0 になるため、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] =>
)