kphpm Posted August 21, 2014 Share Posted August 21, 2014 Hello Again. Sorry i have to ask for help again. Due to the Help in my other topic i managed a lot while working on my webinterface. However now i have a issue again ok here is the array Array ( [0] => Array ( [status] => 3 [ip] => 178.21.114.239 [maxsnapshot] => 5 [hostname] => [password] => 0 [iso] => 14 [tag] => [imageid] => 0 [traffic] => 500 [paymenttypeid] => 0 [ipv6] => 2a02:2308::216:3eff:fe91:1d1e [kernelid] => 0 [bootorder] => 2 [memory] => 1024 [locationid] => 1 [hwid] => 24 [monitoring] => 0 [vpsid] => 1201 [sshkey] => [product] => [type] => 1 [productid] => 32 ) [1] => Array ( [status] => 3 [ip] => 178.21.117.207 [maxsnapshot] => 5 [hostname] => [password] => 0 [iso] => 61 [tag] => [imageid] => 0 [traffic] => 4000 [paymenttypeid] => 0 [ipv6] => 2a02:2308::216:3eff:fe0a:c826 [kernelid] => 0 [bootorder] => 0 [memory] => 8192 [locationid] => 1 [hwid] => 195 [monitoring] => 0 [vpsid] => 1663 [sshkey] => [product] => [type] => 1 [productid] => 36 ) [2] => Array ( [status] => 3 [ip] => 141.105.120.61 [maxsnapshot] => 5 [hostname] => kevin [password] => 1 [iso] => 0 [tag] => Testserver [imageid] => 36 [traffic] => 250 [paymenttypeid] => 0 [ipv6] => 2a02:2308::216:3eff:fe22:3f49 [kernelid] => 27 [bootorder] => 0 [memory] => 512 [locationid] => 1 [hwid] => 52 [monitoring] => 0 [vpsid] => 1967 [sshkey] => [product] => [type] => 2 [productid] => 31 ) ) Now i want to Display the results for example only for the vpsid 1967 , i know i can echo all results with a nested foreach loop but how to look for something inside the array in this case array 2 and display the rest of it? Quote Link to comment Share on other sites More sharing options...
Solution cyberRobot Posted August 21, 2014 Solution Share Posted August 21, 2014 In your loops which display all results, you could add an if test which tests the value of vpsid. If it's equal to 1967, display the entry. Otherwise, skip to the next entry. Quote Link to comment Share on other sites More sharing options...
kphpm Posted August 21, 2014 Author Share Posted August 21, 2014 (edited) so you mean something like this: if($result['vpsid'] == "$row[vpsid]") { ///All other Rows here } else { echo "No Server has been Assigned to you"; } Edited August 21, 2014 by kphpm Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted August 21, 2014 Share Posted August 21, 2014 It's worth a shot. Note that the double quotes aren't needed here: if($result['vpsid'] == "$row[vpsid]") It could be changed to: if($result['vpsid'] == $row['vpsid']) Quote Link to comment Share on other sites More sharing options...
kphpm Posted August 21, 2014 Author Share Posted August 21, 2014 it worked i ended up using this : $server = $directvps->go("get_vpslist"); $server = json_decode($server,true); foreach($server as $result) { if ($result['vpsid'] == $vps) { printf("VPSID: %s<br>Monthly Traffic: %s",$result['vpsid'],$result['traffic']); } } Quote Link to comment 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.