2017-07-26 15 views
1

検索を行い、マルチレイヤー配列で置換する必要があります。私はちょうどそれを働かせることができなかった。私はそれが何か簡単だと分かっています。私は散歩や弦の交換を見なければならない。何も動作していないようです。配列内の値を置き換えるPHP

Iこの配列:

ATWS\AutotaskObjects\QueryResponse Object 
(
    [queryResult] => ATWS\AutotaskObjects\ATWSResponse Object 
     (
      [EntityResults] => ATWS\AutotaskObjects\ArrayOfEntity Object 
       (
        [Entity] => Array 
         (
          [0] => ATWS\AutotaskObjects\Entity Object 
           (
            [Fields] => 
            [UserDefinedFields] => ATWS\AutotaskObjects\ArrayOfUserDefinedField Object 
             (
              [UserDefinedField] => 
             ) 

            [id] => 35 
            [AccountID] => 218 
            [AlertTypeID] => 1 
            [AlertText] => test 
           ) 

          [1] => ATWS\AutotaskObjects\Entity Object 
           (
            [Fields] => 
            [UserDefinedFields] => ATWS\AutotaskObjects\ArrayOfUserDefinedField Object 
             (
              [UserDefinedField] => 
             ) 

            [id] => 36 
            [AccountID] => 218 
            [AlertTypeID] => 2 
            [AlertText] => test2 
           ) 

          [2] => ATWS\AutotaskObjects\Entity Object 
           (
            [Fields] => 
            [UserDefinedFields] => ATWS\AutotaskObjects\ArrayOfUserDefinedField Object 
             (
              [UserDefinedField] => 
             ) 

            [id] => 37 
            [AccountID] => 218 
            [AlertTypeID] => 3 
            [AlertText] => test3 
           ) 

         ) 

       ) 

      [EntityResultType] => accountalert 
      [EntityReturnInfoResults] => ATWS\AutotaskObjects\ArrayOfEntityReturnInfo Object 
       (
        [EntityReturnInfo] => Array 
         (
          [0] => ATWS\AutotaskObjects\EntityReturnInfo Object 
           (
            [DatabaseAction] => None 
            [DuplicateStatus] => ATWS\AutotaskObjects\EntityDuplicateStatus Object 
             (
              [Found] => 
              [Ignored] => 
              [MatchInfo] => 
              [Fields] => 
              [UserDefinedFields] => 
             ) 

            [EntityId] => 35 
            [Message] => 
            [Fields] => 
            [UserDefinedFields] => 
           ) 

          [1] => ATWS\AutotaskObjects\EntityReturnInfo Object 
           (
            [DatabaseAction] => None 
            [DuplicateStatus] => ATWS\AutotaskObjects\EntityDuplicateStatus Object 
             (
              [Found] => 
              [Ignored] => 
              [MatchInfo] => 
              [Fields] => 
              [UserDefinedFields] => 
             ) 

            [EntityId] => 36 
            [Message] => 
            [Fields] => 
            [UserDefinedFields] => 
           ) 

          [2] => ATWS\AutotaskObjects\EntityReturnInfo Object 
           (
            [DatabaseAction] => None 
            [DuplicateStatus] => ATWS\AutotaskObjects\EntityDuplicateStatus Object 
             (
              [Found] => 
              [Ignored] => 
              [MatchInfo] => 
              [Fields] => 
              [UserDefinedFields] => 
             ) 

            [EntityId] => 37 
            [Message] => 
            [Fields] => 
            [UserDefinedFields] => 
           ) 

         ) 

        [Fields] => 
        [UserDefinedFields] => 
       ) 

      [Errors] => ATWS\AutotaskObjects\ArrayOfATWSError Object 
       (
        [ATWSError] => 
        [Fields] => 
        [UserDefinedFields] => 
       ) 

      [ReturnCode] => 1 
     ) 

) 

私は

$replacevalue = 'Jon'; 
function array_replacing(&$item, $key) 
{ 
    if($value== 'test') 
     $item = $replacevalue; 
} 

array_walk_recursive($result, 'array_replacing'); 

を使用しようとしている。しかし働いていない 'はい'

持つすべての単語 'テスト' を交換したいです。私もstr_replaceを試しました。運がない。手伝ってくれますか?

全コード:(マイナス承認)

$authWsdl = 'https://webservices.autotask.net/atservices/1.5/atws.wsdl'; 
$opts = array('trace' => 1); 
$client = new ATWS\Client($authWsdl, $opts); 
$zoneInfo = $client->getZoneInfo($username); 

//print_r($zoneInfo); 

$authOpts = array(
    'login' => $username, 
    'password' => $password, 
    'trace' => 1, // Allows us to debug by getting the XML requests sent 
); 
$wsdl = str_replace('.asmx', '.wsdl', $zoneInfo->getZoneInfoResult->URL); 
$client = new ATWS\Client($wsdl, $authOpts); 

$query = new ATWS\AutotaskObjects\Query('AccountAlert'); 

$Alerttexttoreplace = new ATWS\AutotaskObjects\QueryField('AlertText'); 
$lookvalue = 'test'; 
$Alerttexttoreplace->addExpression('contains', $lookvalue); 

$query->addField($Alerttexttoreplace); 

//$AccountID->$query($AccountID) 
//print_r($AccountID) 
//$updatequery = $query->update($query) 

// If you want to debug the XML produced by the Query object 
// print($query->asXml()); 

// Print the results of the query 
//print_r($client->query($query)); 

//set limited aray 
$result = $client->query($query); 
//print_r ($result); 
//die(); 
$final = $result->queryResult->EntityResults->Entity; 
//print_r ($final); 

//Replace value in array 

$replacevalue = 'Jon'; 

foreach ($final as $key=>$val) 
    { 
     if ($key='AlertText') 
     { 
      //$final = str_replace($lookvalue,$replacevalue,$val=>'AlertText'); 
      echo 'old'; 
      print_r($val); 
      echo 'new'; 
      print_r($newval); 
     } 

    } 





//print_r ($final); 
die(end); 
+0

私は$値は$アイテム – Kodaloid

+0

ノーであるべきだと思う...まだ変化なし。私はどのように変更されていない配列 – jbalter

答えて

1

あなたは$valueを定義していない、単にこれに変更します。

function array_replacing(&$item, $key) 
{ 
    if($item == 'test') 
     $item = $replacevalue; 
} 
+0

にどれくらい深い問題があると思います。 ($キー= 'AlertText') \t \t { \t \t \t $たnewval = str_replace($のlookvalue場合は申し訳ありません – jbalter

+0

私は – jbalter

+0

foreachの($キー=> $ valのように$最終) \t { \t \tのようなものを考えていました、$ replacevalue、$ val => 'AlertText'); \t \t \t echo 'old'; \t \t \t print_r($ val); \t \t \t echo 'new'; \t \t \t print_r($ newval); \t \t \t \t \t – jbalter

関連する問題