我把我的数组中的值作为
$itsthere = (item1-0-100, item2-0-50, item3-0-70, item4-0-50, item5-0-100);
Run Code Online (Sandbox Code Playgroud)
如果用户输入item3他必须得到的值70,那么数组中存在的值.我尝试了很多使用爆炸但它没有显示正确的价值.谁能帮我.
试试:
$itsthere = array(
'item1-0-100',
'item2-0-50',
'item3-0-70',
'item4-0-50',
'item5-0-100'
);
$search = 'item3';
$output = '';
foreach ( $itsthere as $value ) {
if ( strpos($search . '-', $value) === 0 ) {
$output = explode('-', $value)[2];
break;
}
}
Run Code Online (Sandbox Code Playgroud)