SO の多くの回答の中で、「設定を解除」すると配列から要素が削除されることがわかりましたが、このコードを実行した後、まったく異なる結果が見つかりました。インデックス 3 と 4 は存在しないはずですが、存在します。
誰かがこれを説明できますか?
$offset_arr = array();
array_push($offset_arr, array('11','22','33','11','22','33','11','22','33','33','005'));
array_push($offset_arr, array('11','22','33','11','22','33','11','22','33','33','005'));
array_push($offset_arr, array('11','22','33','11','22','33','11','22','33','33','006'));
array_push($offset_arr, array('11','22','33','11','22','33','11','22','33','33','007'));
array_push($offset_arr, array('11','22','33','11','22','33','11','22','33','33','008'));
$temp_arr = make_offset_array_size_smaller($offset_arr);
echo "\n\nafter running a function array size=".count($temp_arr)."\n\n";
print_r($temp_arr);
print_r($temp_arr[4]); // I don't want this. It should work for [2] not [4]
function make_offset_array_size_smaller($input_arr){
$result_arr = array();
$lowest_value = '1000';
foreach($input_arr as $row_arr) {
if((int)($lowest_value) > (int)($row_arr[10])) {
$lowest_value = $row_arr[10];
}
}
$input2_arr = $input_arr;
foreach($input2_arr as $elementKey => $element) {
echo "\n --- ".$elementKey." - ".$element[10];
if((int)($lowest_value) == (int)($element[10])) {
unset($input2_arr[$elementKey]);
}
}
return $input2_arr;
}
結果
--- 0 - 005
--- 1 - 005
--- 2 - 006
--- 3 - 007
--- 4 - 008
after running a function array size=3
Array
(
[2] => Array
(
[0] => 11
[1] => 22
[2] => 33
[3] => 11
[4] => 22
[5] => 33
[6] => 11
[7] => 22
[8] => 33
[9] => 33
[10] => 006
)
[3] => Array
(
[0] => 11
[1] => 22
[2] => 33
[3] => 11
[4] => 22
[5] => 33
[6] => 11
[7] => 22
[8] => 33
[9] => 33
[10] => 007
)
[4] => Array
(
[0] => 11
[1] => 22
[2] => 33
[3] => 11
[4] => 22
[5] => 33
[6] => 11
[7] => 22
[8] => 33
[9] => 33
[10] => 008
)
)
Array
(
[0] => 11
[1] => 22
[2] => 33
[3] => 11
[4] => 22
[5] => 33
[6] => 11
[7] => 22
[8] => 33
[9] => 33
[10] => 008
)