willpower Posted March 2, 2006 Share Posted March 2, 2006 The response I receive from a web service app is in the form of an array. This is set as $result.Heres the first part of code$item=each($result);print_r($item);and this returns the following (sensitive data replacedArray ( [1] => Array ( [Username] => aaaaa [Password] => bbbbb [Forename] => Alex [Surname] => ccccc [Email] => will@xxxx.com [Phone] => 01925xxxxxx[Mobile] => 0780 xxxxxxx [Address1] => 49 xxxxxxx[Address2] => Bxxxxxx [Address3] => Warrington [Address4] => Cheshire [Address5] => xxxxxx [MembershipNumber] => 000056 [PayPointId] => 00000146 ) [value] => Array ( [Username] => aaaaa[Password] => bbbbb [Forename] => Alex [Surname] => xxxxx[Email] => will@xxxxx.com [Phone] => 01925 xxxxx[Mobile] => 0780 xxxxxx[Address1] => 49 xxxxxx[Address2] => xxxxxxxx [Address3] => Warrington [Address4] => Cheshire [Address5] => xxxxxx[MembershipNumber] => 000056 [PayPointId] => 00000146 ) [0] => handleSimpleUserUploadResult [key] => handleSimpleUserUploadResult ) Now you will note that this is a multi dimensional array. For some reason the data seems to appear twice...but Im not that bothered.I simple need to set $membership_no as the [MembershipNumber] valueI have tried but in vain....any help much appreciated.Will Quote Link to comment https://forums.phpfreaks.com/topic/3929-extract-key-value-in-multi-dimensional-array/ Share on other sites More sharing options...
willpower Posted March 2, 2006 Author Share Posted March 2, 2006 come on kenrbnsn ...i know that you can do this...lolWill Quote Link to comment https://forums.phpfreaks.com/topic/3929-extract-key-value-in-multi-dimensional-array/#findComment-13673 Share on other sites More sharing options...
kenrbnsn Posted March 2, 2006 Share Posted March 2, 2006 How did you know I was going to answer this one??? :-)Try this[code]<?php$test = Array ( '1' => Array('Username' => 'aaaaa', 'Password' => 'bbbbb', 'Forename' => 'Alex', 'Surname' => 'ccccc', 'Email' => 'will@xxxx.com', 'Phone' => '01925xxxxxx', 'Mobile' => '0780 xxxxxxx', 'Address1' => '49 xxxxxxx', 'Address2' => 'Bxxxxxx', 'Address3' => 'Warrington', 'Address4' => 'Cheshire', 'Address5' => 'xxxxxx', 'MembershipNumber' => '000056', 'PayPointId' => '00000146'), 'value' => Array ('Username' => 'aaaaa', 'Password' => 'bbbbb', 'Forename' => 'Alex', 'Surname' => 'xxxxx', 'Email' => 'will@xxxxx.com', 'Phone' => '01925 xxxxx', 'Mobile' => '0780 xxxxxx', 'Address1' => '49 xxxxxx', 'Address2' => 'xxxxxxxx', 'Address3' => 'Warrington', 'Address4' => 'Cheshire', 'Address5' => 'xxxxxx', 'MembershipNumber' => '000056', 'PayPointId' => '00000146'), '0' => 'handleSimpleUserUploadResult', 'key' => 'handleSimpleUserUploadResult' );$membership_no = $test[1]['MembershipNumber'];?>[/code]Ken Quote Link to comment https://forums.phpfreaks.com/topic/3929-extract-key-value-in-multi-dimensional-array/#findComment-13695 Share on other sites More sharing options...
willpower Posted March 2, 2006 Author Share Posted March 2, 2006 You would expect that to work...but for a reason beyond my comprhesion it doesn't.The $result is populated by this piece of code$result = $soap_proxy->handleSimpleUserUpload($param);This is how I get the:Array ( [1] => Array ( [Username] => aaaaa [Password] => bbbbb [Forename] => Alex [Surname] => ccccc [Email] => will@xxxx.com [Phone] => 01925xxxxxx[Mobile] => 0780 xxxxxxx [Address1] => 49 xxxxxxx[Address2] => Bxxxxxx [Address3] => Warrington [Address4] => Cheshire [Address5] => xxxxxx [MembershipNumber] => 000056 [PayPointId] => 00000146 ) [value] => Array ( [Username] => aaaaa[Password] => bbbbb [Forename] => Alex [Surname] => xxxxx[Email] => will@xxxxx.com [Phone] => 01925 xxxxx[Mobile] => 0780 xxxxxx[Address1] => 49 xxxxxx[Address2] => xxxxxxxx [Address3] => Warrington [Address4] => Cheshire [Address5] => xxxxxx[MembershipNumber] => 000056 [PayPointId] => 00000146 ) [0] => handleSimpleUserUploadResult [key] => handleSimpleUserUploadResult ) Now it is worth mentioning here that this is all driven by a SOAP Envelope Client (NuSOAP.php) request to a WS server. Although I can't see why that would make a difference. The $param is obviously populated and in turn populating the $result....but I can't extract ANY data from it....just keep getting blank returnsWill Quote Link to comment https://forums.phpfreaks.com/topic/3929-extract-key-value-in-multi-dimensional-array/#findComment-13715 Share on other sites More sharing options...
willpower Posted March 3, 2006 Author Share Posted March 3, 2006 bump Quote Link to comment https://forums.phpfreaks.com/topic/3929-extract-key-value-in-multi-dimensional-array/#findComment-13769 Share on other sites More sharing options...
kenrbnsn Posted March 3, 2006 Share Posted March 3, 2006 After you get the "$result", I assume you're doing a print_r($result). In order to format the output better, do a[code]<?php echo '<pre>' . var_export($result,true) . '</pre>'; ?>[/code]The output will also be valid PHP, so it can be cut and pasted into another program for debugging.I've never played with NuSoap, so I can't help you there.Can you post some of the code?Ken Quote Link to comment https://forums.phpfreaks.com/topic/3929-extract-key-value-in-multi-dimensional-array/#findComment-13785 Share on other sites More sharing options...
willpower Posted March 3, 2006 Author Share Posted March 3, 2006 Wow...the array returned looks normal now.array ( 'handleSimpleUserUploadResult' => array ( 'Username' => 'Banthien.hEynL', 'Password' => 'dfrtMG', 'Forename' => 'Alex', 'Surname' => 'Banthien', 'Email' => 'will@e-rizon.com', 'Phone' => '01925 222 005', 'Mobile' => '0780 392 7771', 'Address1' => '49 Rushton Close', 'Address2' => 'Burtonwood', 'Address3' => 'Warrington', 'Address4' => 'Cheshire', 'Address5' => 'WA5 4HB', 'MembershipNumber' => '000094', 'PayPointId' => '00000184', ),)How do I now extract the membership Number to $membership_noI tried $member_no = $result['MembershipNumber']; //no resultand$new_result= var_export($result,true);$member_no = $new_result['MembershipNumber'];// returned a value of "a"?????Any ideas?Thanks so far Will Quote Link to comment https://forums.phpfreaks.com/topic/3929-extract-key-value-in-multi-dimensional-array/#findComment-13793 Share on other sites More sharing options...
kenrbnsn Posted March 3, 2006 Share Posted March 3, 2006 Since the value you need is in the second level array, you need to do:[code]<?php$member_no = $result[ 'handleSimpleUserUploadResult'][' 'MembershipNumber'];?>[/code]Ken Quote Link to comment https://forums.phpfreaks.com/topic/3929-extract-key-value-in-multi-dimensional-array/#findComment-13808 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.