1
説明:PHPを使用して反復PHPの配列と検証データ
、私は、ユーザーが発信オーダーを作成することができますフォームを持っています。
ユーザーは、特定の顧客に特定のボックス#で送信したい在庫アイテムを選択することができます。
このフォームには、ユーザーが同じボックス#に対して2人の異なる顧客を選択できないようにする必要があるため、このフォームに検証を追加したいと考えています。
例:
Person A -> Item A -> Box 1
Person A -> Item B -> Box 1
Person B -> Item C -> Box 2
Person B -> Item D -> Box 1 //!! <- This should not be possible because
Person C -> Item E -> Box 3 //Person A is already using Box #1.
フォームが送信されると、私はこのような配列を作成しています:
$data = (object) array
(
array (
"customer" => "Person A",
"item" => "Item A",
"box" => "Box 1"
),
array (
"customer" => "Person A",
"item" => "Item B",
"box" => "Box 1"
),
array (
"customer" => "Person B",
"item" => "Item C",
"box" => "Box 2"
),
array (
"customer" => "Person B",
"item" => "Item D",
"box" => "Box 1"
),
array (
"customer" => "Person C",
"item" => "Item E",
"box" => "Box 3"
)
);
質問:
どのように私は、この配列を反復行くのですすべての人が自分のBox#を持っていることを検証しますか?
これは私がしようとしていますが、私は立ち往生午前です:
$temp_arr = (object) array();
foreach($data as $row){
if(!property_exists($temp_arr, $row['customer'])){
$temp_arr->$row['customer'] = array();
};
//Load the boxes into the correct customer array
if(in_array($row['box'], $temp_arr->$row['customer'])){
//Duplicate
} else {
array_push($temp_arr->$row['customer'], $row['box']);
}
}
をその人がアイテムを持っていますが、項目が指摘ボックス#でユーザーに行くべき取らボックス#を使用している場合? – ksealey
既にボックスが使用されている場合、検証は終了し、同じボックスに対して2人の顧客を使用することはできないことを警告します。 – osbt