/    Sign up×
Community /Pin to ProfileBookmark

replace array values

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!

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@jrthor2authorJan 09.2004 — 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.
Copy linkTweet thisAlerts:
@jrthor2authorJan 09.2004 — 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];

}
Copy linkTweet thisAlerts:
@jrthor2authorJan 12.2004 — 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

)

}

}
Copy linkTweet thisAlerts:
@YoNJan 13.2004 — 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:
[code=php]
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";
}
}
}
}
[/code]

Post errors.?

HTH.
Copy linkTweet thisAlerts:
@jrthor2authorJan 14.2004 — cool, that worked. Thanks a bunch!!!
Copy linkTweet thisAlerts:
@YoNJan 14.2004 — Glad to hear that ?
×

Success!

Help @jrthor2 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.14,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...