Click to See Complete Forum and Search --> : arrays


jrthor2
12-09-2003, 01:11 PM
I have a webservice that returns an array of information. If I do a print_r($soapresults) I get the work Array.

On my webservice server page, if I print out $results, I get:

Array
(
[] => Array
(
[00246] => Array
(
[name] => Rite Aid
[store_number] => 00246
[addr1] => 337 West Chocolate Avenue
[city] => Hershey
[state] => PA
[zip] => 17033
[phone_fe] => (717) 533-2941
[phone_ph] => (717) 533-2941
[phone_phf] => (717) 534-0692
[distance] => 2.55
[convenience_foods] => T
[rite_express] => F
[one_hour_photo] => T
[ra_24_hour] => F
[drive_thru_rx] => T
[rite_rewards] => T
[gnc] => T
[western_union] => T
[hours_fe_mon] => 08:00 AM - 10:00 PM
[hours_fe_tue] => 08:00 AM - 10:00 PM
[hours_fe_wed] => 08:00 AM - 10:00 PM
[hours_fe_thu] => 08:00 AM - 10:00 PM
[hours_fe_fri] => 08:00 AM - 10:00 PM
[hours_fe_sat] => 08:00 AM - 10:00 PM
[hours_fe_sun] => 08:00 AM - 10:00 PM
[hours_rx_mon] => 09:00 AM - 09:00 PM
[hours_rx_tue] => 09:00 AM - 09:00 PM
[hours_rx_wed] => 09:00 AM - 09:00 PM
[hours_rx_thu] => 09:00 AM - 09:00 PM
[hours_rx_fri] => 09:00 AM - 09:00 PM
[hours_rx_sat] => 09:00 AM - 07:00 PM
[hours_rx_sun] => 10:00 AM - 06:00 PM
[store_date_open] => 1977-01-16
[store_date_relo] => 1999-02-10
[store_date_reopen] => 9999-12-31
[picture_maker] => T
[photo_ramp] => F
[store_status] => 00
[detail_desc] => Located At 337 West Chocolate Avenue Across From Day's Inn
[division] => E
)

[04287] => Array
(
[name] => Rite Aid
[store_number] => 04287
[addr1] => 360 East Main Street
[city] => Middletown
[state] => PA
[zip] => 17057
[phone_fe] => (717) 944-0262
[phone_ph] => (717) 944-0262
[phone_phf] => (717) 944-7602
[distance] => 4.92
[convenience_foods] => T
[rite_express] => F
[one_hour_photo] => T
[ra_24_hour] => F
[drive_thru_rx] => T
[rite_rewards] => T
[gnc] => T
[western_union] => T
[hours_fe_mon] => 08:00 AM - 10:00 PM
[hours_fe_tue] => 08:00 AM - 10:00 PM
[hours_fe_wed] => 08:00 AM - 10:00 PM
[hours_fe_thu] => 08:00 AM - 10:00 PM
[hours_fe_fri] => 08:00 AM - 10:00 PM
[hours_fe_sat] => 08:00 AM - 10:00 PM
[hours_fe_sun] => 08:00 AM - 10:00 PM
[hours_rx_mon] => 09:00 AM - 09:00 PM
[hours_rx_tue] => 09:00 AM - 09:00 PM
[hours_rx_wed] => 09:00 AM - 09:00 PM
[hours_rx_thu] => 09:00 AM - 09:00 PM
[hours_rx_fri] => 09:00 AM - 09:00 PM
[hours_rx_sat] => 09:00 AM - 07:00 PM
[hours_rx_sun] => 10:00 AM - 06:00 PM
[store_date_open] => 1996-01-04
[store_date_relo] => 2001-04-24
[store_date_reopen] => 9999-12-31
[picture_maker] => F
[photo_ramp] => F
[store_status] => 00
[detail_desc] => Located At 360 East Main Street On The Corner Of Main And Vine Streets
[division] => E
)
}
}

why is it printing the word Array on my webservice client page, and not the array as above?

jrthor2
12-09-2003, 02:13 PM
I also get the error (probably because it is returning the word array):

Warning: Invalid argument supplied for foreach()

here is my code, the error is on the first foreach line:

<?
include "sitecommon.php";
global $zip;

require_once('/home/prgjr1/public_html/ra-new/inc/nusoap.php');
$parameters = array('zip'=>$zip);

$soapclient = new soapclient('http://rawebdev.rss.riteaid.com/prgjr1/ra-new/stores/locator/webservice_server_wsdl.php');

$soapresults = $soapclient->call('rastore',$parameters);
//print_r($soapresults);
/* handle any SOAP faults. */
if ($soapclient->fault) {
echo " Error exist<br>";
echo "FAULT: <p>Code: {$soapclient->faultcode}<br />";
echo "String: {$soapclient->faultactor} <br>";
} else {
//echo "<pre>";
//print_r($soapresults);
//echo "</pre>";
foreach ($soapresults as $arrkey => $arrval) {
//echo "<strong>" . $arrkey . "</strong><br />";
foreach ($arrval as $subkey => $subval) {
//echo "<strong>" . $subkey . "</strong><br />";
//echo "<strong>" . $subval . "</strong><br />";
foreach ($subval as $subsubkey => $subsubval) {
echo "<b>" . $subsubkey . ":</b> " . $subsubval . "<br />";
}
echo "<hr>";
}
echo "<br />";
}
}

//view soap message
echo 'Soap Request: <xmp>'.$soapclient->request.'</xmp>';
echo 'Soap Response: <xmp>'.$soapclient->response.'</xmp>';
//echo 'Soap Debug log: <pre>'.$soapclient->debug_str.'</pre>';

?>

Zibings
12-09-2003, 03:35 PM
Very odd indeed. All I can think of, is maybe it's possible (somehow in this strange strange world) for it to not initiate the array's values on your client page's configuration? That's the only reason I'd think it would only return the word Array.

As I keep thinking about it, are you trying to output any HTML after you attempt to print_r on the client page? See if it does, and if not, it may be causing an error with the parser but isn't showing it???


PS - GO PA!! I live in Mechanicsburg, about 20 min away from Hershey!

jrthor2
12-10-2003, 07:14 AM
do you know anything about webservices and php?

YoN
12-10-2003, 04:20 PM
Hmmm that's a problem i was afraid to happen, if the array isn't full it will error; so, you must check if the variable is an array or not so that it doesn't error but if it's not an array then, it won't echo. try it and see if that's what you want.

Change this code:
foreach ($soapresults as $arrkey => $arrval) {
//echo "<strong>" . $arrkey . "</strong><br />";
foreach ($arrval as $subkey => $subval) {
//echo "<strong>" . $subkey . "</strong><br />";
//echo "<strong>" . $subval . "</strong><br />";
foreach ($subval as $subsubkey => $subsubval) {
echo "<b>" . $subsubkey . ":</b> " . $subsubval . "<br />";
}
echo "<hr>";
}
echo "<br />";
}
to:
if (is_array($soapresults)) {
foreach ($soapresults as $arrkey => $arrval) {
if (is_array($arrval)) {
foreach ($arrval as $subkey => $subval) {
if (is_array($subval)) {
foreach ($subval as $subsubkey => $subsubval) {
echo "<b>" . $subsubkey . ":</b> " . $subsubval . "<br />";
}
}
echo "<hr>";
}
}
echo "<br />";
}
}
Also, i've striped out the commented lines you had. I thought you didn't need them. ;)