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.

eZ debug

Timing: Jan 30 2025 19:42:55
Script start
Timing: Jan 30 2025 19:42:55
Module start 'layout'
Timing: Jan 30 2025 19:42:55
Module start 'content'
Timing: Jan 30 2025 19:42:55
Module end 'content'
Timing: Jan 30 2025 19:42:55
Script end

Main resources:

Total runtime0.0423 sec
Peak memory usage4,096.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0084 588.1016151.1953
Module start 'layout' 0.00840.0052 739.2969220.6641
Module start 'content' 0.01360.0271 959.9609997.7891
Module end 'content' 0.04070.0015 1,957.750033.9766
Script end 0.0422  1,991.7266 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00276.3753140.0002
Check MTime0.00112.5879140.0001
Mysql Total
Database connection0.00071.767610.0007
Mysqli_queries0.005913.965830.0020
Looping result0.00000.045110.0000
Template Total0.00112.610.0011
Template load0.00092.030510.0009
Template processing0.00020.537110.0002
Override
Cache load0.00061.374910.0006
General
dbfile0.004610.910280.0006
String conversion0.00000.020940.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs