我有一个 php 脚本可以做到这一点:
- 将UPC放入表格
- 提交表格
- 检查 UPC 是否已存在于我的数据库中
- 如果是,从 MySQL 数据库中获取它
- 如果没有,请从外部服务器获取它,将其添加到 MySQL 数据库以供将来使用
- 显示结果
它工作正常,但我希望变量看起来与来自 MySQL 缓存或外部服务器的变量完全相同。
当我从服务器打印它时,它看起来像这样:
输出:
[upc] => 066721020215
[pendingUpdates] => 0
[status] => success
[ean] => 0066721020215
[issuerCountryCode] => us
[found] => 1
[description] => Christie - Original Ritz Crackers
[message] => Database entry found
[size] => 225 g
[issuerCountry] => United States
[noCacheAfterUTC] => 2012-08-06T12:23:58
[lastModifiedUTC] => 2009-04-06T01:51:08
但是,当我从 MySQL 打印数组时,它看起来像这样:
$result = mysql_query("SELECT * FROM UPC WHERE `upc` = '$codes[0]'");
$data = mysql_fetch_array($result);
echo "<pre>" . print_r($data, true) . "</pre>";
输出:
[0] => 066721020215
[upc] => 066721020215
[1] => 0
[pendingUpdates] => 0
[2] => success
[status] => success
[3] => 0066721020215
[ean] => 0066721020215
[4] => us
[issuerCountryCode] => us
[5] => 1
[found] => 1
[6] => Christie - Original Ritz Crackers
[description] => Christie - Original Ritz Crackers
[7] => Database entry found
[message] => Database entry found
[8] => 225 g
[size] => 225 g
[9] => United States
[issuerCountry] => United States
[10] => 2012-08-06
[noCacheAfterUTC] => 2012-08-06
[11] => 2009-04-06
[lastModifiedUTC] => 2009-04-06
我意识到这或多或少是外观上的差异(并且数组是需要的两倍大),但是我将如何轻松删除 0、1、2、3 等标识符,而无需遍历数组创建和手动创建一个新的?是否有可以删除编号标识符的功能?