0

Morning!

It's quite early in the morning, so I think the answer of my question will be obvious, but I just can't seem to figure it out.

This is the situation: I have a C# application which communicaties via a WCF webservice with my PHP project. Now, a function in my C# application generates something like this:

stdClass Object ( [GetSpecsResult] => stdClass Object ( 
[string] => Array (
 [0] => 
[1] => Test 
[2] => Test 
[3] => 14-8-2013 10:08:53 
[4] => 14-8-2013 10:08:52 
[5] => 
[6] => ) ) ) 

Basically, what I want is to get the values to print nicely in my PHP project. I could do a foreach within a foreach, this works also, but I'm pretty sure that's not the correct way.

Can someone help me out?

3
  • Goedemorgen! I assume you have multiple entries in that array, that you need a foreach? Commented Aug 20, 2013 at 7:36
  • Nothing wrong with two foreaches. Other than that I don't really get what you're trying to accomplish. Commented Aug 20, 2013 at 7:40
  • What I'm trying to achieve is to print the values within the array into a table. That's why I was thinking of a double foreach, because basically it's an array into an array right? Commented Aug 20, 2013 at 7:44

1 Answer 1

1

The simple way to do this is actually what you say, with a foreach on the array. You do not need a double foreach I think, because you likely only get one stdClass back for the 'GetSpecsResult'.

The clean nice/tidy way is to do this using an iterator on the array but that assumes you: a) have a object model and b) implemented the iterator.

Just go with one/two foreaches, it is the right thing to do!

Sign up to request clarification or add additional context in comments.

2 Comments

Goedemorgen, This is what I use right now: foreach($specsresponse as $key=>$value){ foreach ($value as $key1 => $value1){ // table with values } } But it just.. doesn't look right ;) It works though.
That is fine really. I am not sure about the full format of your result object, but you can probably use foreach($specsresponse['GetSpecsResult'] as $key => $value) - it saves you one foreach, which likely will only run once. Of course this assumes you will only get one SpecsResult, but normally C# works that way (with the wrapping)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.