How to loop through multidimensional array and compare values?How do I check if an array includes an object in JavaScript?How to append something to an array?How to insert an item into an array at a specific index (JavaScript)?How do I determine whether an array contains a particular value in Java?Sort array of objects by string property valueLoop through an array in JavaScriptHow to check if an object is an array?How do I remove a particular element from an array in JavaScript?Loop through an array of strings in Bash?For-each over an array in JavaScript?

What is "oversubscription" in Networking?

Single level file directory

Can one use the present progressive or gerund like an adjective?

How is this practical and very old scene shot?

What exactly did Ant-Man see that made him say that their plan worked?

Can you actually break an FPGA by programming it wrong?

Adjective for 'made of pus' or 'corrupted by pus' or something of something of pus

Do home values typically rise and fall at a consistent percent?

If two black hole event horizons overlap (touch) can they ever separate again?

Is it okay to submit a paper from a master's thesis without informing the advisor?

How receiver knows the exact frequency in the channel to "listen to"?

Thin wall to block LED light from hitting photodiode?

How do we separate rules of logic from non-logical constraints?

Does a return economy-class seat between London and San Francisco release 5.28 tonnes of CO2 equivalents?

Movie with Zoltar in a trailer park named Paradise and a boy playing a video game then being recruited by aliens to fight in space

What game is this character in the Pixels movie from?

What verb for taking advantage fits in "I don't want to ________ on the friendship"?

Handling a player (unintentionally) stealing the spotlight

Why does the recording about Twin Pines Mall not change the same way the newspapers and photographs change?

Warnings of R. Chaim Vital

How to unit test methods which using static methods?

How do I tell the reader that my character is autistic in Fantasy?

I just started should I accept a farewell lunch for a coworker I don't know?

How can I deal with extreme temperatures in a hotel room?



How to loop through multidimensional array and compare values?


How do I check if an array includes an object in JavaScript?How to append something to an array?How to insert an item into an array at a specific index (JavaScript)?How do I determine whether an array contains a particular value in Java?Sort array of objects by string property valueLoop through an array in JavaScriptHow to check if an object is an array?How do I remove a particular element from an array in JavaScript?Loop through an array of strings in Bash?For-each over an array in JavaScript?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








2















I use the PHP script shown below that takes XML data from the Flickr API and gives out an array, but I don't know how to get the values from this array and do some operations with it.



The array has this format:



XmlElement Object
(
[name] => rsp
[attributes] => Array
(
[stat] => ok
)

[content] =>
[children] => Array
(
[0] => XmlElement Object
(
[name] => photos
[attributes] => Array
(
[page] => 1
[pages] => 13751
[perpage] => 100
[total] => 1375086
)

[content] =>
[children] => Array
(
[0] => XmlElement Object
(
[name] => photo
[attributes] => Array
(
[id] => 25000430521
[owner] => 73422502@N08
[secret] => 19459b26e4
[server] => 1703
[farm] => 2
[title] => Health
[ispublic] => 1
[isfriend] => 0
[isfamily] => 0
[url_m] => https://farm2.staticflickr.com/1703/25000430521_19459b26e4.jpg
[height_m] => 500
[width_m] => 500
)

[content] =>
[children] =>
)

[1] => XmlElement Object
(
[name] => photo
[attributes] => Array
(
[id] => 35305743196
[owner] => 73422502@N08
[secret] => 9601255217
[server] => 4232
[farm] => 5
[title] => Health
[ispublic] => 1
[isfriend] => 0
[isfamily] => 0
[url_m] => https://farm5.staticflickr.com/4232/35305743196_9601255217.jpg
[height_m] => 333
[width_m] => 500
)

[content] =>
[children] =>
)



Here is what I try to accomplish:



I try to use these 2 values

´[height_m] => 333 [width_m] => 500´



and use the if construct..



 if (**width_m** / **height_m** >= 1.25 ) 
echo "<img src=" **url_m** " width="100">;

else
echo "<img src=" **url_m** " width="50">;



How do I get this construct in a for each loop?



The code that generates the array comes from an awesome user at php.net



class XmlElement 
var $name;
var $attributes;
var $content;
var $children;
;

function xml_to_object($xml)
$parser = xml_parser_create();
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
xml_parse_into_struct($parser, $xml, $tags);
xml_parser_free($parser);

$elements = array(); // the currently filling [child] XmlElement array
$stack = array();
foreach ($tags as $tag)
return $elements[0]; // the single top-level element










share|improve this question
























  • It would probably be quicker if you used the original XML and didn't bother converting it an array. If you post the original XML then perhaps it would help.

    – Nigel Ren
    Mar 25 at 14:23






  • 1





    Please mark an answer as correct if you got the help you needed. That will mark the question as answered and help keep Stack Overflow nice and clean. If none of the answers worked for you and you have found another solution then submit it as an answer and mark it correct.

    – FabianGillenius
    Mar 27 at 7:33











  • Thank you, I checked it but I did not quite know how to use this code. There are things that I do understand about php already, but I think this is a little bit over beginner level. I will add the code to my question. Sometimes I think its awesome how quick new things can be learned and applied in php but I think I was missing something here,..

    – B. Richardson
    Mar 28 at 3:36












  • Please look at his again @Fabian

    – B. Richardson
    Apr 11 at 20:44












  • @B.Richardson That's some neat code and as expected it creates the XmlElement object that you have shown us in the first code block. However, it does not shed any new light on your question. Have you tried any of the answers you've received? Did they not work for you? Did you get errors? Tell us what went wrong and we might be able to help.

    – FabianGillenius
    Apr 12 at 6:50

















2















I use the PHP script shown below that takes XML data from the Flickr API and gives out an array, but I don't know how to get the values from this array and do some operations with it.



The array has this format:



XmlElement Object
(
[name] => rsp
[attributes] => Array
(
[stat] => ok
)

[content] =>
[children] => Array
(
[0] => XmlElement Object
(
[name] => photos
[attributes] => Array
(
[page] => 1
[pages] => 13751
[perpage] => 100
[total] => 1375086
)

[content] =>
[children] => Array
(
[0] => XmlElement Object
(
[name] => photo
[attributes] => Array
(
[id] => 25000430521
[owner] => 73422502@N08
[secret] => 19459b26e4
[server] => 1703
[farm] => 2
[title] => Health
[ispublic] => 1
[isfriend] => 0
[isfamily] => 0
[url_m] => https://farm2.staticflickr.com/1703/25000430521_19459b26e4.jpg
[height_m] => 500
[width_m] => 500
)

[content] =>
[children] =>
)

[1] => XmlElement Object
(
[name] => photo
[attributes] => Array
(
[id] => 35305743196
[owner] => 73422502@N08
[secret] => 9601255217
[server] => 4232
[farm] => 5
[title] => Health
[ispublic] => 1
[isfriend] => 0
[isfamily] => 0
[url_m] => https://farm5.staticflickr.com/4232/35305743196_9601255217.jpg
[height_m] => 333
[width_m] => 500
)

[content] =>
[children] =>
)



Here is what I try to accomplish:



I try to use these 2 values

´[height_m] => 333 [width_m] => 500´



and use the if construct..



 if (**width_m** / **height_m** >= 1.25 ) 
echo "<img src=" **url_m** " width="100">;

else
echo "<img src=" **url_m** " width="50">;



How do I get this construct in a for each loop?



The code that generates the array comes from an awesome user at php.net



class XmlElement 
var $name;
var $attributes;
var $content;
var $children;
;

function xml_to_object($xml)
$parser = xml_parser_create();
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
xml_parse_into_struct($parser, $xml, $tags);
xml_parser_free($parser);

$elements = array(); // the currently filling [child] XmlElement array
$stack = array();
foreach ($tags as $tag)
return $elements[0]; // the single top-level element










share|improve this question
























  • It would probably be quicker if you used the original XML and didn't bother converting it an array. If you post the original XML then perhaps it would help.

    – Nigel Ren
    Mar 25 at 14:23






  • 1





    Please mark an answer as correct if you got the help you needed. That will mark the question as answered and help keep Stack Overflow nice and clean. If none of the answers worked for you and you have found another solution then submit it as an answer and mark it correct.

    – FabianGillenius
    Mar 27 at 7:33











  • Thank you, I checked it but I did not quite know how to use this code. There are things that I do understand about php already, but I think this is a little bit over beginner level. I will add the code to my question. Sometimes I think its awesome how quick new things can be learned and applied in php but I think I was missing something here,..

    – B. Richardson
    Mar 28 at 3:36












  • Please look at his again @Fabian

    – B. Richardson
    Apr 11 at 20:44












  • @B.Richardson That's some neat code and as expected it creates the XmlElement object that you have shown us in the first code block. However, it does not shed any new light on your question. Have you tried any of the answers you've received? Did they not work for you? Did you get errors? Tell us what went wrong and we might be able to help.

    – FabianGillenius
    Apr 12 at 6:50













2












2








2








I use the PHP script shown below that takes XML data from the Flickr API and gives out an array, but I don't know how to get the values from this array and do some operations with it.



The array has this format:



XmlElement Object
(
[name] => rsp
[attributes] => Array
(
[stat] => ok
)

[content] =>
[children] => Array
(
[0] => XmlElement Object
(
[name] => photos
[attributes] => Array
(
[page] => 1
[pages] => 13751
[perpage] => 100
[total] => 1375086
)

[content] =>
[children] => Array
(
[0] => XmlElement Object
(
[name] => photo
[attributes] => Array
(
[id] => 25000430521
[owner] => 73422502@N08
[secret] => 19459b26e4
[server] => 1703
[farm] => 2
[title] => Health
[ispublic] => 1
[isfriend] => 0
[isfamily] => 0
[url_m] => https://farm2.staticflickr.com/1703/25000430521_19459b26e4.jpg
[height_m] => 500
[width_m] => 500
)

[content] =>
[children] =>
)

[1] => XmlElement Object
(
[name] => photo
[attributes] => Array
(
[id] => 35305743196
[owner] => 73422502@N08
[secret] => 9601255217
[server] => 4232
[farm] => 5
[title] => Health
[ispublic] => 1
[isfriend] => 0
[isfamily] => 0
[url_m] => https://farm5.staticflickr.com/4232/35305743196_9601255217.jpg
[height_m] => 333
[width_m] => 500
)

[content] =>
[children] =>
)



Here is what I try to accomplish:



I try to use these 2 values

´[height_m] => 333 [width_m] => 500´



and use the if construct..



 if (**width_m** / **height_m** >= 1.25 ) 
echo "<img src=" **url_m** " width="100">;

else
echo "<img src=" **url_m** " width="50">;



How do I get this construct in a for each loop?



The code that generates the array comes from an awesome user at php.net



class XmlElement 
var $name;
var $attributes;
var $content;
var $children;
;

function xml_to_object($xml)
$parser = xml_parser_create();
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
xml_parse_into_struct($parser, $xml, $tags);
xml_parser_free($parser);

$elements = array(); // the currently filling [child] XmlElement array
$stack = array();
foreach ($tags as $tag)
return $elements[0]; // the single top-level element










share|improve this question
















I use the PHP script shown below that takes XML data from the Flickr API and gives out an array, but I don't know how to get the values from this array and do some operations with it.



The array has this format:



XmlElement Object
(
[name] => rsp
[attributes] => Array
(
[stat] => ok
)

[content] =>
[children] => Array
(
[0] => XmlElement Object
(
[name] => photos
[attributes] => Array
(
[page] => 1
[pages] => 13751
[perpage] => 100
[total] => 1375086
)

[content] =>
[children] => Array
(
[0] => XmlElement Object
(
[name] => photo
[attributes] => Array
(
[id] => 25000430521
[owner] => 73422502@N08
[secret] => 19459b26e4
[server] => 1703
[farm] => 2
[title] => Health
[ispublic] => 1
[isfriend] => 0
[isfamily] => 0
[url_m] => https://farm2.staticflickr.com/1703/25000430521_19459b26e4.jpg
[height_m] => 500
[width_m] => 500
)

[content] =>
[children] =>
)

[1] => XmlElement Object
(
[name] => photo
[attributes] => Array
(
[id] => 35305743196
[owner] => 73422502@N08
[secret] => 9601255217
[server] => 4232
[farm] => 5
[title] => Health
[ispublic] => 1
[isfriend] => 0
[isfamily] => 0
[url_m] => https://farm5.staticflickr.com/4232/35305743196_9601255217.jpg
[height_m] => 333
[width_m] => 500
)

[content] =>
[children] =>
)



Here is what I try to accomplish:



I try to use these 2 values

´[height_m] => 333 [width_m] => 500´



and use the if construct..



 if (**width_m** / **height_m** >= 1.25 ) 
echo "<img src=" **url_m** " width="100">;

else
echo "<img src=" **url_m** " width="50">;



How do I get this construct in a for each loop?



The code that generates the array comes from an awesome user at php.net



class XmlElement 
var $name;
var $attributes;
var $content;
var $children;
;

function xml_to_object($xml)
$parser = xml_parser_create();
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
xml_parse_into_struct($parser, $xml, $tags);
xml_parser_free($parser);

$elements = array(); // the currently filling [child] XmlElement array
$stack = array();
foreach ($tags as $tag)
return $elements[0]; // the single top-level element







php arrays xml






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 12 at 9:13







B. Richardson

















asked Mar 25 at 14:15









B. RichardsonB. Richardson

275 bronze badges




275 bronze badges












  • It would probably be quicker if you used the original XML and didn't bother converting it an array. If you post the original XML then perhaps it would help.

    – Nigel Ren
    Mar 25 at 14:23






  • 1





    Please mark an answer as correct if you got the help you needed. That will mark the question as answered and help keep Stack Overflow nice and clean. If none of the answers worked for you and you have found another solution then submit it as an answer and mark it correct.

    – FabianGillenius
    Mar 27 at 7:33











  • Thank you, I checked it but I did not quite know how to use this code. There are things that I do understand about php already, but I think this is a little bit over beginner level. I will add the code to my question. Sometimes I think its awesome how quick new things can be learned and applied in php but I think I was missing something here,..

    – B. Richardson
    Mar 28 at 3:36












  • Please look at his again @Fabian

    – B. Richardson
    Apr 11 at 20:44












  • @B.Richardson That's some neat code and as expected it creates the XmlElement object that you have shown us in the first code block. However, it does not shed any new light on your question. Have you tried any of the answers you've received? Did they not work for you? Did you get errors? Tell us what went wrong and we might be able to help.

    – FabianGillenius
    Apr 12 at 6:50

















  • It would probably be quicker if you used the original XML and didn't bother converting it an array. If you post the original XML then perhaps it would help.

    – Nigel Ren
    Mar 25 at 14:23






  • 1





    Please mark an answer as correct if you got the help you needed. That will mark the question as answered and help keep Stack Overflow nice and clean. If none of the answers worked for you and you have found another solution then submit it as an answer and mark it correct.

    – FabianGillenius
    Mar 27 at 7:33











  • Thank you, I checked it but I did not quite know how to use this code. There are things that I do understand about php already, but I think this is a little bit over beginner level. I will add the code to my question. Sometimes I think its awesome how quick new things can be learned and applied in php but I think I was missing something here,..

    – B. Richardson
    Mar 28 at 3:36












  • Please look at his again @Fabian

    – B. Richardson
    Apr 11 at 20:44












  • @B.Richardson That's some neat code and as expected it creates the XmlElement object that you have shown us in the first code block. However, it does not shed any new light on your question. Have you tried any of the answers you've received? Did they not work for you? Did you get errors? Tell us what went wrong and we might be able to help.

    – FabianGillenius
    Apr 12 at 6:50
















It would probably be quicker if you used the original XML and didn't bother converting it an array. If you post the original XML then perhaps it would help.

– Nigel Ren
Mar 25 at 14:23





It would probably be quicker if you used the original XML and didn't bother converting it an array. If you post the original XML then perhaps it would help.

– Nigel Ren
Mar 25 at 14:23




1




1





Please mark an answer as correct if you got the help you needed. That will mark the question as answered and help keep Stack Overflow nice and clean. If none of the answers worked for you and you have found another solution then submit it as an answer and mark it correct.

– FabianGillenius
Mar 27 at 7:33





Please mark an answer as correct if you got the help you needed. That will mark the question as answered and help keep Stack Overflow nice and clean. If none of the answers worked for you and you have found another solution then submit it as an answer and mark it correct.

– FabianGillenius
Mar 27 at 7:33













Thank you, I checked it but I did not quite know how to use this code. There are things that I do understand about php already, but I think this is a little bit over beginner level. I will add the code to my question. Sometimes I think its awesome how quick new things can be learned and applied in php but I think I was missing something here,..

– B. Richardson
Mar 28 at 3:36






Thank you, I checked it but I did not quite know how to use this code. There are things that I do understand about php already, but I think this is a little bit over beginner level. I will add the code to my question. Sometimes I think its awesome how quick new things can be learned and applied in php but I think I was missing something here,..

– B. Richardson
Mar 28 at 3:36














Please look at his again @Fabian

– B. Richardson
Apr 11 at 20:44






Please look at his again @Fabian

– B. Richardson
Apr 11 at 20:44














@B.Richardson That's some neat code and as expected it creates the XmlElement object that you have shown us in the first code block. However, it does not shed any new light on your question. Have you tried any of the answers you've received? Did they not work for you? Did you get errors? Tell us what went wrong and we might be able to help.

– FabianGillenius
Apr 12 at 6:50





@B.Richardson That's some neat code and as expected it creates the XmlElement object that you have shown us in the first code block. However, it does not shed any new light on your question. Have you tried any of the answers you've received? Did they not work for you? Did you get errors? Tell us what went wrong and we might be able to help.

– FabianGillenius
Apr 12 at 6:50












2 Answers
2






active

oldest

votes


















0














The simplest approach I can conceive (change "$Object" to the variable name of your XMLElement Object):



foreach($Object->children[0]->children as $child) 
if ($child->attributes['width_m'] / $child->attributes['height_m'] >= 1.25 )
echo "<img src=" . $child->attributes['url_m'] . " width="100">;

else
echo "<img src=" . $child->attributes['url_m'] . " width="50">;







share|improve this answer






























    0














    This is not a foreach loop but it will essentiall do the same thing:



    $allImageHtml = array_map(function($photoData)
    $width = ($photoData->attributes['width_m'] / $photoData->attributes['height_m']) >= 1.25 ?100:50;
    return "<img src='$child->attributes['url_m'] width='$width'/>";
    , $Object->children[0]->children);

    echo implode('<!-- Separator HTML. (ie: br) -->', $allImageHtml);


    Alternatively if you would prefer a foreach loop:



    foreach($Object->children[0]->children as $photoData)
    $width = ($photoData->attributes['width_m'] / $photoData->attributes['height_m']) >= 1.25 ? 100: 50;
    $spacer = "<!-- Separator HTML. (ie: br) -->";
    echo "<img src='$child->attributes['url_m'] width='$width'/>$spacer";






    share|improve this answer



























      Your Answer






      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "1"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55339850%2fhow-to-loop-through-multidimensional-array-and-compare-values%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      The simplest approach I can conceive (change "$Object" to the variable name of your XMLElement Object):



      foreach($Object->children[0]->children as $child) 
      if ($child->attributes['width_m'] / $child->attributes['height_m'] >= 1.25 )
      echo "<img src=" . $child->attributes['url_m'] . " width="100">;

      else
      echo "<img src=" . $child->attributes['url_m'] . " width="50">;







      share|improve this answer



























        0














        The simplest approach I can conceive (change "$Object" to the variable name of your XMLElement Object):



        foreach($Object->children[0]->children as $child) 
        if ($child->attributes['width_m'] / $child->attributes['height_m'] >= 1.25 )
        echo "<img src=" . $child->attributes['url_m'] . " width="100">;

        else
        echo "<img src=" . $child->attributes['url_m'] . " width="50">;







        share|improve this answer

























          0












          0








          0







          The simplest approach I can conceive (change "$Object" to the variable name of your XMLElement Object):



          foreach($Object->children[0]->children as $child) 
          if ($child->attributes['width_m'] / $child->attributes['height_m'] >= 1.25 )
          echo "<img src=" . $child->attributes['url_m'] . " width="100">;

          else
          echo "<img src=" . $child->attributes['url_m'] . " width="50">;







          share|improve this answer













          The simplest approach I can conceive (change "$Object" to the variable name of your XMLElement Object):



          foreach($Object->children[0]->children as $child) 
          if ($child->attributes['width_m'] / $child->attributes['height_m'] >= 1.25 )
          echo "<img src=" . $child->attributes['url_m'] . " width="100">;

          else
          echo "<img src=" . $child->attributes['url_m'] . " width="50">;








          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 25 at 14:25









          FabianGilleniusFabianGillenius

          5265 silver badges13 bronze badges




          5265 silver badges13 bronze badges























              0














              This is not a foreach loop but it will essentiall do the same thing:



              $allImageHtml = array_map(function($photoData)
              $width = ($photoData->attributes['width_m'] / $photoData->attributes['height_m']) >= 1.25 ?100:50;
              return "<img src='$child->attributes['url_m'] width='$width'/>";
              , $Object->children[0]->children);

              echo implode('<!-- Separator HTML. (ie: br) -->', $allImageHtml);


              Alternatively if you would prefer a foreach loop:



              foreach($Object->children[0]->children as $photoData)
              $width = ($photoData->attributes['width_m'] / $photoData->attributes['height_m']) >= 1.25 ? 100: 50;
              $spacer = "<!-- Separator HTML. (ie: br) -->";
              echo "<img src='$child->attributes['url_m'] width='$width'/>$spacer";






              share|improve this answer





























                0














                This is not a foreach loop but it will essentiall do the same thing:



                $allImageHtml = array_map(function($photoData)
                $width = ($photoData->attributes['width_m'] / $photoData->attributes['height_m']) >= 1.25 ?100:50;
                return "<img src='$child->attributes['url_m'] width='$width'/>";
                , $Object->children[0]->children);

                echo implode('<!-- Separator HTML. (ie: br) -->', $allImageHtml);


                Alternatively if you would prefer a foreach loop:



                foreach($Object->children[0]->children as $photoData)
                $width = ($photoData->attributes['width_m'] / $photoData->attributes['height_m']) >= 1.25 ? 100: 50;
                $spacer = "<!-- Separator HTML. (ie: br) -->";
                echo "<img src='$child->attributes['url_m'] width='$width'/>$spacer";






                share|improve this answer



























                  0












                  0








                  0







                  This is not a foreach loop but it will essentiall do the same thing:



                  $allImageHtml = array_map(function($photoData)
                  $width = ($photoData->attributes['width_m'] / $photoData->attributes['height_m']) >= 1.25 ?100:50;
                  return "<img src='$child->attributes['url_m'] width='$width'/>";
                  , $Object->children[0]->children);

                  echo implode('<!-- Separator HTML. (ie: br) -->', $allImageHtml);


                  Alternatively if you would prefer a foreach loop:



                  foreach($Object->children[0]->children as $photoData)
                  $width = ($photoData->attributes['width_m'] / $photoData->attributes['height_m']) >= 1.25 ? 100: 50;
                  $spacer = "<!-- Separator HTML. (ie: br) -->";
                  echo "<img src='$child->attributes['url_m'] width='$width'/>$spacer";






                  share|improve this answer















                  This is not a foreach loop but it will essentiall do the same thing:



                  $allImageHtml = array_map(function($photoData)
                  $width = ($photoData->attributes['width_m'] / $photoData->attributes['height_m']) >= 1.25 ?100:50;
                  return "<img src='$child->attributes['url_m'] width='$width'/>";
                  , $Object->children[0]->children);

                  echo implode('<!-- Separator HTML. (ie: br) -->', $allImageHtml);


                  Alternatively if you would prefer a foreach loop:



                  foreach($Object->children[0]->children as $photoData)
                  $width = ($photoData->attributes['width_m'] / $photoData->attributes['height_m']) >= 1.25 ? 100: 50;
                  $spacer = "<!-- Separator HTML. (ie: br) -->";
                  echo "<img src='$child->attributes['url_m'] width='$width'/>$spacer";







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Mar 25 at 14:36

























                  answered Mar 25 at 14:31









                  Miroslav GlamuzinaMiroslav Glamuzina

                  2,8922 gold badges12 silver badges23 bronze badges




                  2,8922 gold badges12 silver badges23 bronze badges



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55339850%2fhow-to-loop-through-multidimensional-array-and-compare-values%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                      Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                      Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript