前几行只是为了仔细检查所有变量是否符合要求。他们都给出了正确的数据。
print_r($stack) 确实给出了上述数组元素,(+ 和更多元素)
<?php
$item_name = $_POST['item_name'];
echo $item_name.'<br/><br/>'; // IBM-3246785
print_r($stack); // Array ( [0] => IBM-3246785 [1] => IBM-3567465 [2] => IBM-4579645 [3] => [4] => IBM-1234567 [5] => [6] => IBM-12345678 [7] => [8] => IBM-24374365 )
$key = array_search($item_name, $stack);
if ($key !== false) {
echo "The key where find was found is:" . $key;
} else{
echo $item_name . " was NOT FOUND in the array";
};
?>
数组搜索每次都返回错误!!!尝试用 IBM-3246785 替换 $item_name - 问题仍然存在。无法让它返回所选“item_name”的索引/键。