F
F
FRATEREH2022-04-17 17:20:51
PHP
FRATEREH, 2022-04-17 17:20:51

Retrieving all elements of a loop?

Somewhere I'm stupid.

I need to display all the elements of the cycle in $jko2 and $jko3, now it displays the last one and I understand that it just follows it and writes the final value, yes, I understand that I can write it to an empty array [] but I don’t understand what is the point of this, when I need to extract it and in fact I will come to the same + in jkk I can’t do foreach because in fact this is the value of the variable itself, which is then returned, so I also understand that I can add . = instead of just assigning = but then it will just add info every time and it doesn't make much sense


Thank you for your help!

PS With regards to html, I can't embed php pieces in it because I do it on wp and output the final function to a shortcode that is executed on a simple html page without php

JSON

"data": {
"id": 7338,
"notification_id": 1272,
"member_name": "Russian Federation",
"member_code": "C643",
"document_symbol": "G\/MA\/QR\/N\/RUS\/5",
"qr_serial_number": 5,
"qr_group": 753665709,
"measures": [{
"symbol": "P",
"label": "Prohibition",
"products": [{
"hs_version": "HS-17",
"chapter": "37",
"code": "3706",
"reported_code": "ex 3706",
"description": "Cinematographic film, exposed and developed, whether or not incorporating soundtrack or consisting only of soundtrack",
"reported_description": "Printed and audiovisual products containing calls to extremist and terrorist activity or public justification of terrorism",
"interpreted": 0
}, {
"hs_version": "HS-17",
"chapter": "49",
"code": "4901",
"reported_code": "ex 4901",
"description": "Printed books, brochures and similar printed matter, whether or not in single sheets (excl. periodicals and publications which are essentially devoted to advertising)",
"reported_description": "Printed and audiovisual products containing calls to extremist and terrorist activity or public justification of terrorism",
"interpreted": 0
}] }, {
"symbol": "P-X",
"label": "Prohibition",
"products": [{
"hs_version": "HS-17",
"chapter": "37",
"code": "3706",
"reported_code": "ex 3706",
"description": "Cinematographic film, exposed and developed, whether or not incorporating soundtrack or consisting only of soundtrack",
"reported_description": "Printed and audiovisual products containing calls to extremist and terrorist activity or public justification of terrorism",
"interpreted": 0
}, {
"hs_version": "HS-17",
"chapter": "49",
"code": "4901",
"reported_code": "ex 4901",
"description": "Printed books, brochures and similar printed matter, whether or not in single sheets (excl. periodicals and publications which are essentially devoted to advertising)",
"reported_description": "Printed and audiovisual products containing calls to extremist and terrorist activity or public justification of terrorism",
"interpreted": 0
}]
}],
"administrative_mechanisms": "Administered by the Federal Customs Service",
"national_legal_bases": "Decision of the Board of the Eurasian Economic Commission \u2116 30 of April 21; 2015; as last amended and adjusted",
"description": "Import and export prohibition of printed information or information on audio-visual and other devices",
"period_from_dt": "01\/10\/2020",
"period_to_dt": "30\/09\/2022",
"in_force_dt": "01\/10\/2021",
"wto_agreements": [{
"agreement_code": "026",
"agreement_source": "GATT",
"agreement_label": "GATT 1994",
"agreement_web_link": "http:\/\/www.wto.org\/english\/docs_e\/legal_e\/gatt47_01_e.htm",
"article_code": "021802",
"article_element_code": 2,
"article_description": "XX:(a) - (a) necessary to protect public morals;",
"article_element_label": "BODY",
"article_footnote": "",
"article_index": "Article XX:(a)"
}, {
"agreement_code": "026",
"agreement_source": "GATT",
"agreement_label": "GATT 1994",
"agreement_web_link": "http:\/\/www.wto.org\/english\/docs_e\/legal_e\/gatt47_01_e.htm",
"article_code": "021904",
"article_element_code": 2,
"article_description": "XXI:(c) - (c) to prevent any contracting party from taking any action in pursuance of its obligations under the United Nations Charter for the maintenance of international peace and security.",
"article_element_label": "BODY",
"article_footnote": "",
"article_index": "Article XXI:(c)"
}],
"non_wto_agreements": []
}
}


PHP Foreach
foreach ($dfs as $dfs2){
if ($dfs2['administrative_mechanisms'][0]):
$rop = '<h4>Administrative Mechanisms</h4>'.$dfs2['administrative_mechanisms'].'';	
endif;	
foreach ($dfs2['wto_agreements'] as $dfs3):
$jko2 = '<span style="color:#fff;">Agreement Label:</span> '.$dfs3['agreement_label'].'</span><br><span style="color:#fff;">Article Code:</span> <a href="'.$dfs3['agreement_web_link'].'" target="_blank" style="color:#00aeff">'.$dfs3['article_code'].'</a></span><br><span style="color:#fff;">Article Index:</span> '.$dfs3['article_index'].'</span><br><span style="color:#fff;">Article Description:</span> '.$dfs3['article_description'].'</span></dd>';
endforeach;
foreach ($dfs2['measures'] as $dfs4){ 
$jko4 = '<span style="color:#fff;">Label:</span> '.$dfs4['label'].'<br><span style="color:#fff;">Symbol:</span> '.$dfs4['symbol'].'';
foreach ($dfs4['products'] as $dfs5){
$jko3 = '<span style="color:#fff;">HS Version:</span> '.$dfs5['hs_version'].'<br><span style="color:#fff;">Code:</span> '.$dfs5['code'].'<br><span style="color:#fff;">Description:</span> '.$dfs5['description'].'<br><span style="color:#fff;">Reported Description:</span> '.$dfs5['reported_description'].'';
}}
$jkk .= '<dt><span>'.$dfs2['description'].'</span><div class="acc-icon-wrap parallax-wrap"><div class="acc-button-icon parallax-element"><i class="fa fa-angle-down"></i></div></div></dt><dd class="accordion-content"><h4>Document Symbol</h4>'.$dfs2['document_symbol'].'<h4>National Legal Bases</h4>'.$dfs2['national_legal_bases'].''.$rop.'<h4>Relevance</h4><span style="color:#fff;">Date From:</span> '.$dfs2['period_from_dt'].' <span style="color:#fff;">Date To:</span> '.$dfs2['period_to_dt'].' <span style="color:#fff;">In Force</span> '.$dfs2['in_force_dt'].'<h4>Measures</h4>'.$jko4.'<h4>Products</h4>'.$jko3.'<h4>WTO Agreements</h4>'.$jko2.'';
}
return $jkk;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Elena, 2022-04-19
@lenk0belk0

You need an operator .=in loops.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question