0

配列に構築しているという応答があります。元の応答から特定の ID を取得して、別のレスト コネクタを作成する必要がありました。コードは次のようになります (変数名で失礼します。しばらくするとアイデアが尽きてしまいます)。

foreach ($newArray as $r=>$p){
foreach ($p as $t=>$hoop){


checksession();
$restNew2 = new RESTConnector();


$urlNew2 = "https://localhost:9630/api/users/".$p['user']."/";
$restNew2->createRequest($urlNew2,"GET", null, $_SESSION['cookies'][0]);
$restNew2->sendRequest();


$responseNew2 = $restNew2->getResponse();

$xmlNew2 = new SimpleXMLElement($responseNew2);


$newerArray = array();
foreach ($xmlNew2->children() as $newestChild){
    for($g=0, $count2 = count($xmlNew2); $g < $count2; $g++) {
    $userID = (string)$xmlNew2['id'];
    $first[] = (string)$xmlNew2->name->first;
    $last[] = (string)$xmlNew2->name->last;
$newerArray[$g]['first'] = $first[$g];

}

}
}
}

配列を印刷すると、次のようになります。

Array
(
[0] => Array
    (
        [first] => LightSpeed
    )

[1] => Array
    (
        [first] => LightSpeed
    )

[2] => Array
    (
        [first] => LightSpeed
    )

[3] => Array
    (
        [first] => LightSpeed
    )

[4] => Array
    (
        [first] => LightSpeed
    )

[5] => Array
    (
        [first] => LightSpeed
    )

[6] => Array
    (
        [first] => LightSpeed
    )

[7] => Array
    (
        [first] => LightSpeed
    )

[8] => Array
    (
        [first] => LightSpeed
    )

[9] => Array
    (
        [first] => LightSpeed
    )

[10] => Array
    (
        [first] => LightSpeed
    )

[11] => Array
    (
        [first] => LightSpeed
    )

[12] => Array
    (
        [first] => LightSpeed
    )

[13] => Array
    (
        [first] => LightSpeed
    )

[14] => Array
    (
        [first] => LightSpeed
    )

[15] => Array
    (
        [first] => LightSpeed
    )

[16] => Array
    (
        [first] => LightSpeed
    )

[17] => Array
    (
        [first] => LightSpeed
    )

[18] => Array
    (
        [first] => LightSpeed
    )
}

ユーザー名を取得しようとしている 18 の請求書がありますが、ユーザー名はすべて異なるはずです。print_r($first} (応答に含まれるユーザーのファースト ネーム) を実行すると、さまざまなユーザー名が表示されるほぼ 2,000 の配列エントリが表示されます。これを何時間もいじっていて、取得できません。ヘルプ!

4

1 に答える 1

0

これを試して:

$xmlNew2 = new SimpleXMLElement($responseNew2);
$new_array = json_decode(json_encode($xmlNew2));

次にループし$new_arrayます。その方が扱いやすいはずです。

于 2012-08-24T04:07:02.883 に答える