Re: String to Array or Hash Table

From: Date: Sun, 19 Oct 2003 16:03:11 +0000
Subject: Re: String to Array or Hash Table
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-166663@lists.php.net to get a copy of this message
sun zheng said: > tx for the reply.. ya, it is what i am looking for.. however, your solution > is not the right one.. please help me to adjust it a lot.. > > let us come back to the initial string .. > "approved=yes&error=&authnumber=025968&transactionnumber=313869"; > I definately want to get something like > $value_array['approved'] is "yes" > $value_array['error'] is "" > $value_array['authnumber'] is "025968" > $value_array['transactionnumber'] is "313869" If I'm wrong, blame this on coming into the thread at this stage, not the beginning. That string look suspiciously like a GET request. $myvars = array('approved', 'error', 'authnumber', 'transactionnumber'); foreach ($myvars as $key) { $value_array[$key] = $_GET[$key]; } If it's just a string, something like: $data_array = split('&', $string); foreach ($data_array as $key) { list($mykey, $value) = split('=', $key); $value_array[$mykey] = $value; } More than one way to skin a cat, and my foreach loops are probably wrong. Simple application of the manual really, in the end.

« previous php.general (#166663) next »