Accessing Array Element

Author Message

Anaya P

Monday 31 January 2011 5:51:31 am

Hi there,

I am getting data from SOAP Response as below -

array(4) {
  ["sLegType"]=>
  string(9) "Departure"
  ["sAirCode"]=>
  string(2) "DL"
  ["sAirName"]=>
  string(15) "Delta Air Lines"
  ["ClassInfo"]=>
  array(2) {
    [0]=>
    array(3) {
      ["eClassType"]=>
      string(1) "B"
      ["sCPS"]=>
      string(5) "13.39"
      ["sWPS"]=>
      string(4) "2460"
    }
    [1]=>
    array(3) {
      ["eClassType"]=>
      string(1) "E"
      ["sCPS"]=>
      string(4) "6.56"
      ["sWPS"]=>
      string(4) "1206"
    }
  }
}


array(4) {
  ["sLegType"]=>
  string(9) "Departure"
  ["sAirCode"]=>
  string(2) "KL"
  ["sAirName"]=>
  string(24) "KLM-Royal Dutch Airlines"
  ["ClassInfo"]=>
  array(2) {
    [0]=>
    array(3) {
      ["eClassType"]=>
      string(1) "B"
      ["sCPS"]=>
      string(5) "13.39"
      ["sWPS"]=>
      string(4) "2460"
    }
    [1]=>
    array(3) {
      ["eClassType"]=>
      string(1) "E"
      ["sCPS"]=>
      string(4) "6.56"
      ["sWPS"]=>
      string(4) "1206"
    }
  }
}

Want to display eClassType info against AIr line name. Really do not know how to access it?

In short, I want to display data in below format -

Airline Name First Class Business Class Economy Class Premium Economy Class

Delta Air - 13.39 6.56 -

KLM - 13.39 6.56 -

I have tried foreach statements, but had no luck.

Appreciate your advice guys.

Thanks

Anaya.

Thiago Campos Viana

Monday 31 January 2011 8:21:47 am

Hi Anaya

First you need to check if you assigned the variable to a template variable, If yes you could use {$varName|attrbiute(show,1)} to show if your var has the right content, then you could just show the content in this way:

{foreach $varName as $value}

<div>

{$value.sLegType} - {$value.ClassInfo[0].sCPS} {$value.ClassInfo[1].sCPS} -

</div>

{/foreach}

eZ Publish Certified Developer: http://auth.ez.no/certification/verify/376924

Twitter: http://twitter.com/tcv_br

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.