I get response from the server in Simple XML, but I want get to my page only data I need and show this data in html tags. How I can do it?
My request code:
include "TopSdk.php";
date_default_timezone_set('Asia/Shanghai');
$c = new TopClient;
$c->appkey = '*******';
$c->secretKey = '***************';
$req = new AliexpressAffiliateProductQueryRequest;
$req->setAppSignature("1111");
$req->setFields("sale_price");
$req->setKeywords("car");
$req->setMaxSalePrice(300);
$req->setMinSalePrice(150);
$req->setPageNo(1);
$req->setPageSize(2);
$req->setSort("SALE_PRICE_ASC");
$req->setTargetCurrency("USD");
$req->setTargetLanguage("en");
$req->setTrackingId("trackID");
echo "<pre>";
var_dump($c->execute($req));
echo "</pre>";
Server response in SXML:
object(SimpleXMLElement)#2717 (2) {
["resp_result"]=>
object(SimpleXMLElement)#2486 (3) {
["resp_code"]=>
string(3) "200"
["resp_msg"]=>
string(13) "Call succeeds"
["result"]=>
object(SimpleXMLElement)#2500 (4) {
["current_page_no"]=>
string(1) "1"
["current_record_count"]=>
string(1) "2"
["products"]=>
object(SimpleXMLElement)#2493 (1) {
["product"]=>
array(2) {
[0]=>
object(SimpleXMLElement)#2434 (29) {
["app_sale_price"]=>
string(4) "1.50"
["app_sale_price_currency"]=>
string(3) "USD"
["commission_rate"]=>
string(4) "9.0%"
["discount"]=>
string(3) "80%"
["first_level_category_id"]=>
string(2) "34"
["first_level_category_name"]=>
string(32) "Automobiles, Parts & Accessories"
["hot_product_commission_rate"]=>
string(4) "0.0%"
["lastest_volume"]=>
string(1) "0"
["original_price"]=>
string(4) "7.50"
["original_price_currency"]=>
string(3) "USD"
["product_detail_url"]=>
string(53) "https://www.aliexpress.com/item/1005002897604484.html"
["product_id"]=>
string(16) "1005002897604484"
["product_main_image_url"]=>
string(65) "https://ae04.alicdn.com/kf/H251d6cd1fb6b457f86d9418c8fb69bfc4.jpg"
["product_small_image_urls"]=>
object(SimpleXMLElement)#2431 (1) {
["string"]=>
array(6) {
[0]=>
string(65) "https://ae04.alicdn.com/kf/H251d6cd1fb6b457f86d9418c8fb69bfc4.jpg"
[1]=>
string(65) "https://ae04.alicdn.com/kf/Hef9247dcda18452b86cec742dc6e1512T.jpg"
[2]=>
string(65) "https://ae04.alicdn.com/kf/H0c39946d5ce345feb6f8fe2785157a2aw.jpg"
[3]=>
string(65) "https://ae04.alicdn.com/kf/H46444b25ac824ca48144ce8a41de8df1E.jpg"
[4]=>
string(65) "https://ae04.alicdn.com/kf/Hd5ec838b5f2544b3a21827f2751bcf48y.jpg"
[5]=>
string(65) "https://ae04.alicdn.com/kf/H550518786e1a472ebc1cf0b8cfdc522f2.jpg"
}
}
["product_title"]=>
string(163) "Car Parasol Front Windshield Side Window Cover Interior UV-protective Curtain шторки для автомобиля шторка для автомобилей "
["promotion_link"]=>
string(807) "https://s.click.aliexpress.com/s/4BScZUQRCtnCPCxSv0PKwEvDQD4u6TRQDsTl9yY3LPNpjcFJYJYgdvBwDDpTrktMG0Bk7vaKjL6XyPRVpHoWa7nQNlQFkqJPggCvZt8DKU9umyHh6eIX5opg0KuXEYNPi7ieG5LeqJDbqOacEd03kB7TjoPS5lw5oIH5JFWbhzN203U3K2CHxLHglZ3KrbYkGRGOE1cgm0v2oQRL2P5WzsJEV9UY7mMsJJsfwdoEo4YKzpQ4A6hFKY1Q4wYvOojPSfj2bFrEVwvkPSR5Y6FnaSrCZc6K5dZ2jfPZN2c5Uz6ken8DkMcl0at0TpyWMnasTOgxAit4gFga3NDjwESqiUlIktUrZigriucp0TyWz5DmYrGN654flY9yNmmuVez6QNmDok6kjJHM2iFZeBpJBYwSpaEMGvA21M0pjyJqLzq0lO7917WednH9wn4FJlFBHs5yGVX2PaCvU9EH41B3YaDNHDfKWP9aj0XcvBrV85e7h6Zukmu3erQ1h85q1gaClmOGLuF1rrw8w5b4j4NoikPBrUQlBXFQxH8B6bISevyTUl95U1uWA7Gt4uk4ySEEqlsHQLrcVwcF70ySnxuoDQ5dCf6LjaoOs8SOMJRm6I8SippRCihNz7PiLXmfmhyaTO6Bcff1hHQ4xIa4bwasbnh5IL3kF3MobRZBYCinXezrYyhCxlXrqw1GbFYwJ1dc9NGGSwU33s6x8XBpjUzib5y5uE1NVAwTBFCdwOewHMKpebf9e5El5yOT9IQBp2tp2O7zWr"
["relevant_market_commission_rate"]=>
string(4) "3.0%"
["sale_price"]=>
string(4) "1.50"
["sale_price_currency"]=>
string(3) "USD"
["second_level_category_id"]=>
string(9) "200003411"
["second_level_category_name"]=>
string(20) "Interior Accessories"
["shop_id"]=>
string(9) "912064829"
["shop_url"]=>
string(42) "https://www.aliexpress.com/store/912064829"
["target_app_sale_price"]=>
string(4) "1.50"
["target_app_sale_price_currency"]=>
string(3) "USD"
["target_original_price"]=>
string(4) "7.50"
["target_original_price_currency"]=>
string(3) "USD"
["target_sale_price"]=>
string(4) "1.50"
["target_sale_price_currency"]=>
string(3) "USD"
}
[1]=>
object(SimpleXMLElement)#2432 (29) {
["app_sale_price"]=>
string(4) "1.35"
["app_sale_price_currency"]=>
string(3) "USD"
["commission_rate"]=>
string(4) "9.0%"
["discount"]=>
string(3) "73%"
["first_level_category_id"]=>
string(2) "34"
["first_level_category_name"]=>
string(32) "Automobiles, Parts & Accessories"
["hot_product_commission_rate"]=>
string(4) "0.0%"
["lastest_volume"]=>
string(1) "0"
["original_price"]=>
string(4) "5.00"
["original_price_currency"]=>
string(3) "USD"
["product_detail_url"]=>
string(53) "https://www.aliexpress.com/item/1005003402966179.html"
["product_id"]=>
string(16) "1005003402966179"
["product_main_image_url"]=>
string(65) "https://ae04.alicdn.com/kf/Hd263fbbd1dad4d49a3a3277261c6c408L.jpg"
["product_small_image_urls"]=>
object(SimpleXMLElement)#2431 (1) {
["string"]=>
array(5) {
[0]=>
string(65) "https://ae04.alicdn.com/kf/Hd263fbbd1dad4d49a3a3277261c6c408L.jpg"
[1]=>
string(65) "https://ae04.alicdn.com/kf/H3595b1b670c04d8b95307ad54f30ee5ac.jpg"
[2]=>
string(65) "https://ae04.alicdn.com/kf/Hbc1076a0bbca4f91a60d8eb27f9392547.jpg"
[3]=>
string(65) "https://ae04.alicdn.com/kf/H999a513e61be49d2ad374fa87e4f34897.jpg"
[4]=>
string(65) "https://ae04.alicdn.com/kf/H7e29d629b6d04ec8870f166a71cf87212.jpg"
}
}
["product_title"]=>
string(124) "2022 New Car Interior Accessories Car Perfume Aromatherapy Cute Crown Teddy Bear Air Outlet Plaster Bear Ornament Decoration"
["promotion_link"]=>
string(807) "https://s.click.aliexpress.com/s/4BScZUQRCtnCPCxSv0PKwEvDQD4u6TRQDsTl9yY3LPNpjcFJYJYgdvBwDDpTrktMG0Bk7vaKjL6XyPRVpHoWa7nQNlQFkqJPggCvZt8DKU9umyHh6eIX5opg0KuXEYNPi7ieG5LeqJDbqOacEd03kB7TjoPS5lw5oIH5JFWbhzN203U3K2CHxLHglZ3KrbYkGRGOE1cgm0v2oQRL2P5WzsJEV9UY7mMsJJsfwdoEo4YKzpQ4A6hFKY1Q4wYvOojPSfj2bFrEVwvkPSR5Y6FnaSrCZc6K5dZ2jfPZN2c5Uz6ken8DkMcl0at0TpyYdHF0HQtA8jRRgCMGPA1XaVUh1IydbFgJOCvwetULs4d0J8ib9Xni5t3QrUNsxQ3lSARntkxnshpruYkDmzb3HJ3sf9GyH5rTL3OTC0dpG3XfbyCmQI7sE1rDkdWSBbIvIHJXWaawBxtuhmqr6WfjZDNeYY0JfdgUsh9F8OqLed1uePoqJHK8FdFG6GAnXwZkCbS84viXRSeHP4EjjjC4Z7gtBzNveIjurnHopaqkY4FNXnJzdGJwnudZyXpX7pV7jkaygdr7GnlfsroGM4P1e8GnFgcimWdqfV0vg71vTxlBJmVDSrtmndZVpTXu3dfIZbjuIyWZWwlCrKCxWbqsppQYItz8662L6l9uKNJLIoKipN0ZTyWkGA2XYBg9al3sPUsO39aTK7ZnxOr3SWOk8Zo6Ua3q3v6UemjvLqqruSU46TCFydPTWxg9wegSuYctUTY0MgdLen"
["relevant_market_commission_rate"]=>
string(4) "3.0%"
["sale_price"]=>
string(4) "1.35"
["sale_price_currency"]=>
string(3) "USD"
["second_level_category_id"]=>
string(9) "200003411"
["second_level_category_name"]=>
string(20) "Interior Accessories"
["shop_id"]=>
string(9) "912521256"
["shop_url"]=>
string(42) "https://www.aliexpress.com/store/912521256"
["target_app_sale_price"]=>
string(4) "1.35"
["target_app_sale_price_currency"]=>
string(3) "USD"
["target_original_price"]=>
string(4) "5.00"
["target_original_price_currency"]=>
string(3) "USD"
["target_sale_price"]=>
string(4) "1.35"
["target_sale_price_currency"]=>
string(3) "USD"
}
}
}
["total_record_count"]=>
string(6) "472235"
}
}
["request_id"]=>
string(12) "iirdj5wwp91x"
}
I need for example olny strings: Title["product_title"], Price["sale_price"] and TrackID["promotion_link"], how I can get it's? And show on web page only this data:
<h1>Title</h1>
<h2>Price</h2>
<a href>TrackID</a>
Thanks!
try this.
$content = "xml content";
$xml = new \SimpleXMLElement($content);
foreach($xml->resp_result->result->products->product as $product) {
echo "<h1>" . $product->product_title . "</h1>";
echo "<h2>" . $product->sale_price . "</h2>";
echo "<a href>" . $product->promotion_link . "</a>";
}
if not running or error, check if php-xml module as installed.
Related
I have an array returned from Google Maps, that looks like this:
array(4) {
["destination_addresses"]=> array(4) {
[0]=> string(19) "Walsall WS2 9PS, UK"
[1]=> string(19) "Walsall WS2 9PS, UK"
[2]=> string(19) "Walsall WS2 9PS, UK"
[3]=> string(26) "Wolverhampton WV10 0QP, UK"
}
["origin_addresses"]=> array(1) {
[0]=> string(18) "Stone ST15 0FL, UK"
}
["rows"]=> array(1) {
[0]=> array(1) {
["elements"]=> array(4) {
[0]=> array(3) {
["distance"]=> array(2) {
["text"]=> string(7) "41.9 km"
["value"]=> int(41947)
}
["duration"]=> array(2) {
["text"]=> string(7) "36 mins"
["value"]=> int(2134)
}
["status"]=> string(2) "OK"
}
[1]=> array(3) {
["distance"]=> array(2) {
["text"]=> string(7) "41.9 km"
["value"]=> int(41947)
}
["duration"]=> array(2) {
["text"]=> string(7) "36 mins"
["value"]=> int(2134)
}
["status"]=> string(2) "OK"
}
[2]=> array(3) {
["distance"]=> array(2) {
["text"]=> string(7) "41.9 km"
["value"]=> int(41947)
}
["duration"]=> array(2) {
["text"]=> string(7) "36 mins"
["value"]=> int(2134)
}
["status"]=> string(2) "OK"
}
[3]=> array(3) {
["distance"]=> array(2) {
["text"]=> string(7) "40.9 km"
["value"]=> int(40924)
}
["duration"]=> array(2) {
["text"]=> string(7) "41 mins"
["value"]=> int(2458)
}
["status"]=> string(2) "OK"
}
}
}
}
["status"]=> string(2) "OK"
}
I want to be able to run through the array, and print the destination address and the distance and time values.
This prints the destination addresses ok:
$length=count($properties);
for($a=0;$a<$length;$a++)
{
echo '</br>Index is ' . $a . ' | id is ' . $index[$a] . ' | destination is ' . $properties["destination_addresses"][$a] . ' | time is ';
}
But I can't figure out how to print the rest. I've been banging my head against the wall all night!
Thank you in anticipation.
To loop over all these journeys and print the distance and time for each potential journey, create a foreach loop and then use the $idx to address the subordinate parts of the muleiple arrays
foreach( $destination['destination_addresses'] as $idx => $to ) {
if ( $destination['rows'][0]['elements'][$idx]['status'] == 'OK' ) {
echo 'Going from ' . $destination['origin_addresses'][0];
echo ' To ' . $to;
echo ' Distance ' . $destination['rows'][0]['elements'][$idx]['distance']['text'];
echo ' Duration ' . $destination['rows'][0]['elements'][$idx]['duration']['text'];
} else {
//whatever you do if the status is not OK
}
}
I have written below lines of code
public function shiftarray($cursor, $arg)
{
$keyarguments = array("first_name","roll_no");
$arrayStudents =array();
foreach ($cursor as $k => $row)
{
foreach ($keyarguments as $key)
{
if (strcasecmp($row[$key], $arg) == 0)
{
array_unshift($arrayStudents, $row);
}
else
{
}
}
}
return $arrayStudents;
}
I have array of students in $cursor like
{ [0]=> array(50) { ["_id"]=> object(MongoId)#23 (1) { ["$id"]=> string(24) "58131c7799fbad4c1d000202" } ["student_id"]=> float(2) ["registration_temp_perm_no"]=> string(1) "1" ["roll_no"]=> float(1) ["admission_date"]=> string(10) "01/07/2016" ["first_name"]=> string(7) "Neil" ["middle_name"]=> string(4) "David" ["last_name"]=> string(6) "Stephan" ["dob"]=> string(10) "12/03/1981" ["gender"]=> string(6) "Female" ["blood_group"]=> string(2) "A+" ["birth_place"]=> string(11) "Sadar Bazar" ["nationality"]=> string(6) "Indian" ["language"]=> string(7) "English" ["religion"]=> string(8) "Agnostic" ["address_line1"]=> string(20) "4148 Hazelcrest Hill" ["address_line2"]=> string(20) "22883 Memorial Place" ["city"]=> string(11) "Sadar Bazar" ["state"]=> string(13) "Uttar Pradesh" ["pincode"]=> string(6) "190010" ["country"]=> string(5) "India" ["phone1"]=> string(10) "9039180419" ["phone2"]=> string(10) "7681559402" ["email"]=> string(24) "educianstudent#gmail.com" ["is_sms_enabled"]=> string(3) "Yes" ["is_active"]=> int(1) ["has_finished"]=> int(0) ["student_category"]=> string(1) "5" ["course"]=> string(24) "58131c7099fbad4c1d0001c2" ["Biometric_ID"]=> string(1) "1" ["siblings"]=> string(14) "Cynthia Taylor" ["guardian_name"]=> string(14) "Cynthia Taylor" ["guardian_occupation"]=> string(13) "Senior Editor" ["guardian_qualification"]=> string(20) "Research Assistant I" ["guardian_email_id"]=> string(23) "educianparent#gmail.com" ["gaurdain_contact_details"]=> string(10) "9419513603" ["guardian_relationship"]=> string(6) "Father" ["height"]=> string(3) "4.9" ["weight"]=> string(4) "34.9" ["allergies"]=> string(0) "" ["batch"]=> int(2) ["academicyear"]=> string(4) "2015" ["batchhistory"]=> array(1) { [0]=> array(5) { ["batchid"]=> float(2) ["academic_year"]=> string(4) "2015" ["course"]=> string(24) "58131c7099fbad4c1d0001c2" ["sequenceno"]=> int(1) ["courseId"]=> object(MongoId)#24 (1) { ["$id"]=> string(24) "58131c7099fbad4c1d0001c2" } } } ["uploads"]=> array(1) { ["profile_pic"]=> string(39) "58131c7799fbad4c1d000202schoolgirl2.jpg" } ["created_at"]=> NULL ["updated_at"]=> string(0) "" ["routearray"]=> array(2) { [0]=> array(5) { ["routeid"]=> int(2) ["academicyear"]=> string(4) "2016" ["current"]=> int(0) ["vehicleno"]=> string(9) "JK01S8764" ["dateofassignment"]=> string(10) "09/28/2016" } [1]=> array(5) { ["routeid"]=> int(3) ["academicyear"]=> string(4) "2016" ["current"]=> int(1) ["vehicleno"]=> string(9) "JK01S8764" ["dateofassignment"]=> string(10) "11/17/2016" } } ["HostelAlloted"]=> array(7) { ["Food Preferences"]=> string(4) "Both" ["Hostel"]=> object(MongoId)#25 (1) { ["$id"]=> string(24) "58138aee99fbade41e000031" } ["Floor"]=> string(7) "Floor_1" ["RoomNumber"]=> int(11) ["Approved"]=> string(3) "yes" ["Approved On"]=> object(MongoDate)#26 (2) { ["sec"]=> int(1472322600) ["usec"]=> int(0) } ["Academic Year"]=> string(4) "2016" } ["HostelAllotmentHistory"]=> array(1) { [0]=> array(7) { ["Food Preferences"]=> string(4) "Both" ["Hostel"]=> object(MongoId)#27 (1) { ["$id"]=> string(24) "58138aee99fbade41e000031" } ["Floor"]=> string(7) "Floor_1" ["RoomNumber"]=> int(11) ["Approved"]=> string(3) "yes" ["Approved On"]=> object(MongoDate)#28 (2) { ["sec"]=> int(1472322600) ["usec"]=> int(0) } ["Academic Year"]=> string(4) "2016" } } ["courseId"]=> object(MongoId)#29 (1) { ["$id"]=> string(24) "58131c7099fbad4c1d0001c2" } }
...
...
I am trying to bring those student on the beginning of array whose first name is brian and rest of students should at the bottom.
Now the above code place the students on the top of the array but the rest of the students are ommited/removed. I don't want them to be removed.
I am trying to tweak what code to write in else condition.
Please help!!!
Fill $arrayStudents before the loop otherwise only matches will be collected and unshifted.
Extend example of php.net/unshift
$add = array('big');
$queue = array(
array("orange"),
array("banana"),
array("apple1"),
array("raspberry")
);
array_unshift($queue, $add);
print_r($queue);
In your case: search for keys you want to unshift, the rest goes to the standard $list = array(/list of studends/):
$list = array();
$bringToTop = array('brian', 'elvis');
foreach($data as $item) {
if (/* in in the list to bring on top*/) {
$memory[] = $item;
} else {
$list[] = $item;
}
}
foreach($memory as $item) {
array_unshift($list, $item);
}
print_r($list);
Kind regards
Add $arrayStudents[] = $row; to your else scope. Here is a simple demo to illustrate it.
When matches add the element to the result from the start of array, unmatches add them from the end of the array.
I am using the PHP specific SOAPClient in order to call for a soap API and get responses.
The problem I have is that I do not manage to get in order the results, neither to extract them.
The code I am using is:
<?php
$wsdl = 'http://portalquery.just.ro/Query.asmx?wsdl';
$client = new SoapClient($wsdl);
$xml_array['numarDosar'] = '10080/3/2013';
$response = $client->CautareDosare2($xml_array);
var_dump($response);
?>
The results I get are:
object(stdClass)#2 (1) { ["CautareDosare2Result"]=> object(stdClass)#3 (1) { ["Dosar"]=> array(2) { [0]=> object(stdClass)#4 (13) { ["parti"]=> object(stdClass)#5 (1) { ["DosarParte"]=> array(3) { [0]=> object(stdClass)#6 (2) { ["nume"]=> string(22) "Mocanu Andrei Cristian" ["calitateParte"]=> string(17) "Recurent Inculpat" } [1]=> object(stdClass)#7 (2) { ["nume"]=> string(21) "Mocanu Răzvan George" ["calitateParte"]=> string(17) "Recurent Inculpat" } [2]=> object(stdClass)#8 (2) { ["nume"]=> string(11) "Mica Marian" ["calitateParte"]=> string(17) "Recurent Inculpat" } } } ["sedinte"]=> object(stdClass)#9 (1) { ["DosarSedinta"]=> object(stdClass)#10 (9) { ["complet"]=> string(26) "S2 Complet urgentă recurs" ["data"]=> string(19) "2013-03-14T00:00:00" ["ora"]=> string(5) "12:00" ["solutie"]=> string(14) "Respins recurs" ["solutieSumar"]=> string(408) "Înc. 82/R/În majoritate :Respinge ca nefondate recursurile declararate de recurenţii inculpaţi Mocanu Andrei Cristian, Mocanu Răzvan George şi Mica Marian. Obligă pe fiecare recurent la câte 300 lei cheltuieli judiciare către stat. Pronunţată în şedinţă publică, azi, 14.03.2013. Opinie separată în sensul admiterii recursurilor şi luării măsurii obligării de a nu părăsi localitatea." ["dataPronuntare"]=> string(19) "2013-03-14T00:00:00" ["documentSedinta"]=> string(33) "incheieremasuripreventivefazadeUP" ["numarDocument"]=> string(7) "82/2013" ["dataDocument"]=> string(19) "2013-03-14T00:00:00" } } ["numar"]=> string(12) "10080/3/2013" ["numarVechi"]=> string(8) "831/2013" ["data"]=> string(19) "2013-03-14T00:00:00" ["institutie"]=> string(21) "CurteadeApelBUCURESTI" ["departament"]=> string(22) "Secţia a II-a penală" ["categorieCaz"]=> string(5) "Penal" ["stadiuProcesual"]=> string(6) "Recurs" ["obiect"]=> string(113) "prelungirea duratei arestării preventive dispuse în cursul urmăririi penale (art. 156 şi următoarele C.p.p.)" ["dataModificare"]=> string(23) "2017-01-18T06:48:34.467" ["categorieCazNume"]=> string(5) "Penal" ["stadiuProcesualNume"]=> string(6) "Recurs" } [1]=> object(stdClass)#11 (14) { ["parti"]=> object(stdClass)#12 (1) { ["DosarParte"]=> array(3) { [0]=> object(stdClass)#13 (2) { ["nume"]=> string(22) "MOCANU ANDREI CRISTIAN" ["calitateParte"]=> string(8) "Inculpat" } [1]=> object(stdClass)#14 (2) { ["nume"]=> string(20) "MOCANU RAZVAN GEORGE" ["calitateParte"]=> string(8) "Inculpat" } [2]=> object(stdClass)#15 (2) { ["nume"]=> string(11) "MICA MARIAN" ["calitateParte"]=> string(8) "Inculpat" } } } ["sedinte"]=> object(stdClass)#16 (1) { ["DosarSedinta"]=> object(stdClass)#17 (9) { ["complet"]=> string(5) "CC1 -" ["data"]=> string(19) "2013-03-12T00:00:00" ["ora"]=> string(5) "23:59" ["solutie"]=> string(12) "Soluţionare" ["solutieSumar"]=> string(311) "În baza prevederilor art. 155 şi urm. C.p.p. dispune prelungirea măsurii arestării preventive a inculpaţilor Mocanu Andrei Cristian, Mocanu Răzvan George şi Mica Marius pe o perioadă de 20 de zile, de la 15.03.2013 - 03.04.2013, inclusiv. Cu recurs. Pronunţată în şedinţă publică azi, 12.03.2013." ["dataPronuntare"]=> string(19) "2013-03-12T00:00:00" ["documentSedinta"]=> string(27) "incheierefinaladezinvestire" ["numarDocument"]=> string(0) "" ["dataDocument"]=> string(19) "2013-03-12T00:00:00" } } ["caiAtac"]=> object(stdClass)#18 (1) { ["DosarCaleAtac"]=> object(stdClass)#19 (3) { ["dataDeclarare"]=> string(19) "2013-03-13T00:00:00" ["parteDeclaratoare"]=> string(37) " MICA MARIAN, MOCANU RAZVAN GEORGE, " ["tipCaleAtac"]=> string(6) "Recurs" } } ["numar"]=> string(12) "10080/3/2013" ["numarVechi"]=> string(0) "" ["data"]=> string(19) "2013-03-11T00:00:00" ["institutie"]=> string(19) "TribunalulBUCURESTI" ["departament"]=> string(22) "Secţia a-II-a Penală" ["categorieCaz"]=> string(5) "Penal" ["stadiuProcesual"]=> string(4) "Fond" ["obiect"]=> string(113) "prelungirea duratei arestării preventive dispuse în cursul urmăririi penale (art. 156 şi următoarele C.p.p.)" ["dataModificare"]=> string(23) "2017-01-18T08:33:50.877" ["categorieCazNume"]=> string(5) "Penal" ["stadiuProcesualNume"]=> string(4) "Fond" } } } }
I tried to explode on the results, also used $response[1]->array and such, nothing works.
<?php
ini_set("display_errors", 1);
$wsdl = 'http://portalquery.just.ro/Query.asmx?wsdl';
$client = new SoapClient($wsdl);
$xml_array['numarDosar'] = '10080/3/2013';
$response = $client->CautareDosare2($xml_array);
$resultArray= json_decode(json_encode($response),true);
$arrayOnfirstKey=$resultArray[key($resultArray)];
$arrayOnSecondKey= $arrayOnfirstKey[key($arrayOnfirstKey)];
echo "<table>";
echo "<tr>";
echo "<td>nume</td>";
echo "<td>CalitateParte</td>";
echo "</tr>";
foreach($arrayOnSecondKey as $value)
{
foreach($value["parti"]["DosarParte"] as $data)
{
echo "<tr>";
echo "<td>" .$data["nume"]."</td>";
echo "<td>" .$data["calitateParte"]."</td>";
echo "</tr>";
}
}
echo "</table>";
array(10) {
["table_name"]=>
string(0) ""
["chart_type"]=>
string(5) "Table"
["chart_name"]=>
string(9) "Veterans "
["dashboard_name"]=>
string(7) "Default"
["data_option"]=>
string(0) ""
["limit_value"]=>
string(1) "0"
["view_status"]=>
bool(true)
["view_priority"]=>
string(0) ""
["chart_data"]=>
array(72) {
[0]=>
array(11) {
[0]=>
string(4) "Rank"
[1]=>
string(6) "Branch"
[2]=>
string(12) "Level 3 Name"
[3]=>
string(12) "Level 4 Name"
[4]=>
string(23) "Logged Premia Score MTD"
[5]=>
string(26) "Converted Premia Score MTD"
[6]=>
string(21) "Persistancy Score MTD"
[7]=>
string(23) "Logged Premia Score YTD"
[8]=>
string(26) "Converted Premia Score YTD"
[9]=>
string(21) "Persistancy Score YTD"
[10]=>
string(5) "Score"
}
[1]=>
array(11) {
[0]=>
float(1)
[1]=>
string(22) " GWALIOR DIRECTSegment"
[2]=>
string(29) "G00563 - GOVIND SINGH KUSHWAH"
[3]=>
string(21) "S03643 - Shishir Jain"
[4]=>
float(1)
[5]=>
float(1)
[6]=>
float(1)
[7]=>
float(0.9994)
[8]=>
float(1)
[9]=>
float(1)
[10]=>
float(9.89901)
}
[2]=>
array(11) {
[0]=>
float(2)
[1]=>
string(26) " KURUKSHETRA DIRECTSegment"
[2]=>
string(23) "A02311 - Amarjeet Singh"
[3]=>
string(21) "S00927 - Sachin Kumar"
[4]=>
float(1)
[5]=>
float(1)
[6]=>
float(1)
[7]=>
float(0.953)
[8]=>
float(1)
[9]=>
float(1)
[10]=>
float(9.82245)
}
}
["color_scheme_name"]=>
string(7) "Default"
}
How do i display the chart_data in php
$arr=json_decode($row[0],TRUE);
var_dump($arr);
foreach($arr as $row)
{
foreach($row['chart_data'] as $k)
{
echo $k['Rank'];
echo $k['Branch'];
}
}
EDIT:
for ($x=0; $x<=count
($arr['chart_data']); $x++) {
foreach($arr['chart_data'][$x] as $key=>$val)
{
echo $val;
}
}
You are having 2 foreach calls.
The first one passes all keys of the outer array, amongst which chart_data.
The second one looks at the children of the outer array, and looks for chart_data in each child. But is obviously not finding any.
Change your code to this:
$arr=json_decode($row[0],TRUE);
foreach($arr['chart_data'] as $k){
echo $k['Rank'];
echo $k['Branch'];
}
edit:
I see. (Thanks for indenting your array) Your problem is off course that $arr['rank']and $arr['branch'] don't exist. They are mere strings inside $k[0] and $k[1] and themselves don't contain any other data.
What would you have like to see outputted?
Maybe this is solution.
$arr = json_decode($row[0],TRUE);
foreach($row['chart_data'] as $chart_data)
{
foreach($chart_data[0] as $k)
{
echo $k['Rank'];
echo $k['Branch'];
}
}
Update :
Rank, Branch is values. Your array is bad format.
$arr = json_decode($row[0],TRUE);
foreach($row['chart_data'] as $chart_data)
{
foreach($chart_data[0] as $k)
{
echo $k[0];
echo $k[1];
}
}
i have the following array:
[2]=>
object(stdClass)#9 (4) {
["ID"]=>
string(32) "43c845f895a56fbe8aea9435ef8fa806"
["Type"]=>
string(8) "Campaign"
["Name"]=>
string(28) "An unmissable invitation for"
["Actions"]=>
array(5) {
[0]=>
object(stdClass)#10 (4) {
["Event"]=>
string(4) "Open"
["Date"]=>
string(19) "2013-05-07 17:00:00"
["IPAddress"]=>
string(12) "109.239.93.2"
["Detail"]=>
string(0) ""
}
[1]=>
object(stdClass)#11 (4) {
["Event"]=>
string(4) "Open"
["Date"]=>
string(19) "2013-05-07 09:01:00"
["IPAddress"]=>
string(12) "109.239.93.2"
["Detail"]=>
string(0) ""
}
[2]=>
object(stdClass)#12 (4) {
["Event"]=>
string(4) "Open"
["Date"]=>
string(19) "2013-04-30 22:29:00"
["IPAddress"]=>
string(14) "94.171.192.216"
["Detail"]=>
string(0) ""
}
[3]=>
object(stdClass)#13 (4) {
["Event"]=>
string(5) "Click"
["Date"]=>
string(19) "2013-04-30 17:43:00"
["IPAddress"]=>
string(12) "109.239.93.2"
["Detail"]=>
string(60) "http://www.rbh.co.uk/rbhevent/?name=[fullname]&email=[email]"
}
[4]=>
object(stdClass)#14 (4) {
["Event"]=>
string(4) "Open"
["Date"]=>
string(19) "2013-04-30 17:43:00"
["IPAddress"]=>
string(12) "109.239.93.2"
["Detail"]=>
string(0) ""
}
}
}
i am trying to count the events that are the same. So for example ["Event"] = Open =4 / ["Event"] = Click =1.
I am trying to achieve this via counting a foreach loop:
$i=0;
foreach($entry->Actions as $actions ) {
echo $i++;
}
Im not quite sure how to approach this? Can someone suggest a best practice?
$counts = array();
foreach($entry->Actions as $actions) {
if(!isset($counts[$actions->Event])) {
$counts[$actions->Event] = 0;
}
++$counts[$actions->Event];
}
print_r($counts);
<?php
$amounts = array(); // Events as key
foreach($entry->Actions as $actions)
{
if (isset($amounts[$actions["Event"]])) $amounts[$actions["Event"]]++;
else $amounts[$actions["Event"]] = 1;
}
print_r($amounts);
echo "<br>".$amounts["Open"];
?>