Click to See Complete Forum and Search --> : replace array values


jrthor2
01-09-2004, 01:21 PM
I have an array that look slike this:

[store_number] => 00866
[addr1] => 501 South 29th Street
[city] => Harrisburg
[state] => PA
[zip] => 17104
[phone_fe] => (717) 233-5344
[phone_ph] => (717) 233-5344
[phone_phf] => (717) 236-5095
[distance] => 2.25
[convenience_foods] => F
[rite_express] => F
[one_hour_photo] => F
[ra_24_hour] => F
[drive_thru_rx] => T
[rite_rewards] => T
[gnc] => F
[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] => 1986-09-01
[store_date_relo] => 1987-03-27
[store_date_reopen] => 9999-12-31
[picture_maker] => F
[photo_ramp] => F
[store_status] => 00
[detail_desc] => Located At 501 South 29th Street Next To Giant Across From Weis
[division] => E

I need to to get the T and F values replaced with true or false. How can I do this without replacing other occurances of T or F that are actual words, like in the detail_desc?

Thanks!

pyro
01-09-2004, 01:49 PM
I believe I presented the concept to you here: http://forums.webdeveloper.com/showthread.php?s=&threadid=24181#post125672

jrthor2
01-09-2004, 02:12 PM
Well, it is not working for some reason. I guess I forgot about this since I got no response back, but it still does not replace the values.

jrthor2
01-09-2004, 02:25 PM
Here is my updated code, it is now priting out the array for me, but the values are not being replaced with "true"/"false".

function rastore($zip){

if (!strlen($zip)) {
return new soap_fault('Client','','Please supply a valid zip code.');
} else {
//call class to call mapquest
$CC=new mystorelookup;
$CC->find_stores_by_zip($zip);
$cnt = count($CC->$stores);
if ( count($CC->$stores) > 0 ) {
//print_r($CC->$stores);
$results[$i] = $CC->$stores[$i];
} else if ( count($CC->$stores) == 0 ) {
return new soap_fault('Client','','No results were found');
}
}
//$back = "it works";
//print_r($results);


foreach ($results[$i] as $key => $value) {
if (trim($value == "T")) {
$results[$i][$key] = "true";
}
else if (trim($value == "F")) {
$results[$i][$key] = "false";
}
}

echo "<pre>";
print_r($results[$i]);
echo "</pre>";
return $results[$i];
}

jrthor2
01-12-2004, 08:01 AM
can anyone help me here??

Here is a sample of what the array looks like:

Array
(
[] => Array
(
[00246] => Array
(
[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
)
}
}

YoN
01-13-2004, 05:56 PM
As that is a multi-dimentional array, I think that you need to get a bit deeper in the array... try this for the 'foreach' loop:

foreach ($results[$i] as $key => $value) {
if (is_array($value)) {
foreach ($value as $key2 => $value2) {
if (trim($value2 == "T")) {
$results[$i][$key][$key2] = "true";
} else if (trim($value2 == "F")) {
$results[$i][$key][$key2] = "false";
}
}
}
}

Post errors.;)
HTH.

jrthor2
01-14-2004, 07:11 AM
cool, that worked. Thanks a bunch!!!

YoN
01-14-2004, 04:21 PM
Glad to hear that :)