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++;
}
但它给我一个错误说“注意:试图获取非对象的属性”
谁能帮我解决这个问题。
问候海莉