dpxyfa4718 2012-09-21 12:00
浏览 26
已采纳

如何在另一个页面中获取数组值[关闭]

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));

    }

    }

In page1 i am calling the function with one argument. In the page2 i am keeping the results in an associate array.

When I am printing the array from page1 its showing me output as

Array
(
[vc] => Array
    (
        [0] => CB
        [1] => RD
        [2] => RT
        [3] => YX
    )

[vi] => Array
    (
        [0] => 01461 
        [1] => 95101 
        [2] => 30818 
        [3] => 77126 
    )

)

i wanted to use the array in page1 like this

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++;
}    

but it is throwing me an error saying " Notice: Trying to get property of non-object "

Can any one please help me how to solve this issues.

Regards Hailey

  • 写回答

1条回答 默认 最新

  • doutan4831 2012-09-21 12:07
    关注

    $final is an array, access the value like this :

    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++;
    }    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 关于#html5#的问题:H5页面用户手机返回的时候跳转到指定页面例如(语言-javascript)
  • ¥15 无法使用此凭据登录,因为你的域不可用,如何解决?(标签-Windows)
  • ¥15 yolov9的训练时间
  • ¥15 二叉树遍历没有报错但无法正常运行
  • ¥15 在linux系统下vscode运行robocup3d上场球员报错
  • ¥15 Python语言实验
  • ¥15 SAP HANA SQL 增加合计行
  • ¥20 用C#语言解决一个英文打字练习器,有偿
  • ¥15 srs-sip外部服务 webrtc支持H265格式
  • ¥15 在使用abaqus软件中,继承到assembly里的surfaces怎么使用python批量调动