page1.php
$destinationCity = $_POST['destination'];
$sr = new searchArray();
$final = $sr->searcharray($destinationCity);
echo "<pre>";
print_r($final);
echo $final->vc[0];
echo "</pre>";Page2.php
class searchArray {
public function searcharray($arr) {
$rst = array();
$length = strlen($arr);
if ($length == 2){
$sql = "select code from ukhotels where postcode LIKE '$arr%'";
$rsd = mysql_query($sql);
while($rs = mysql_fetch_array($rsd)){
$co = $rs['code'];
$vc = &$rst['vc'];
$vi = &$rst['vi'];
$vc[] = substr($co, 0, 2);
$vi[] = substr($co, 3, strlen($co));
}
}在page1中,我使用一个参数调用函数。在page2中,我将结果保存在一个关联数组中。
当我从page1打印数组时,它将输出显示为
Array
(
[vc] => Array
(
[0] => CB
[1] => RD
[2] => RT
[3] => YX
)
[vi] => Array
(
[0] => 01461
[1] => 95101
[2] => 30818
[3] => 77126
)
)我想像这样使用page1中的数组
for($i=0, $j=1;$i<=20;$i++)
{
$params["VendorLocation"]["VendorCode"] = "{$final->vc[$i]}";
$params["VendorLocation"]["VendorLocationID"] = "{$final->vi[$i]}";
$params["VendorLocation"]["Key"] = "{$j}";
$j++;
} 但是它抛给我一个错误,说“通知:试图获取非对象的属性”
有谁能帮我解决这个问题吗?
问候Hailey
发布于 2012-09-21 20:07:44
$final是一个数组,取值如下:
for($i=0, $j=1; $i<=20; $i++) {
$params["VendorLocation"]["VendorCode"] = '{' . $final['vc'][$i] . '}';
$params["VendorLocation"]["VendorLocationID"] = '{' . $final['vi'][$i] . '}';
$params["VendorLocation"]["Key"] = "{$j}";
$j++;
} https://stackoverflow.com/questions/12530196
复制相似问题