Home >Backend Development >PHP Tutorial >Notice: Undefined index: sku in PHP problem solution_PHP tutorial

Notice: Undefined index: sku in PHP problem solution_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:11:481032browse

Notice: Undefined index: sku in PHP Problem Solution

This is not a bug, but a warning. When using $_GET[] or $_POST[] without adding isset or other judgments, this error will be prompted. The solution suggested by Jones perfectly solves this problem:

/*
 * 取代$_GET[]获取值
 */
function _get($str) {
	$val = !empty($_GET[$str]) ? $_GET[$str] : null;
	return $val;
}

/*
 * 取代$_POST[]获取值
 */
function _post($str) {
	$val = !empty($_POST[$str]) ? $_POST[$str] : null;
	return $val;
}

When using, the usage is as follows:

/** 设置当前页数 */
$page = _get('page');
$inventory->setCurrentPage($page);

/** 计算总页数 */
$sku = _post('sku');
$warehouse = _post('warehouse');
$supplier = _post('supplier');

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/926457.htmlTechArticleNotice in PHP: Undefined index: sku in Problem solution This is not a bug, but a warning, use $_GET[ ] or $_POST[] without adding isset or other judgments, this error will be prompted, Jon...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn