0

I'm working on web service which is supposed to return two arrays to my iOS application, is this possible with one PHP class in the web service development?

apaul
  • 15,557
  • 8
  • 44
  • 76
Malloc
  • 12,816
  • 31
  • 101
  • 184

3 Answers3

5

Yes, it is possible, however it will require some creativity. My recommendation is that you wrap your two arrays in another array, and return that single array to your iOS application.

EXAMPLE:

$array1 = array("1","2","3");
$array2 = array("4","4","6");
$array3 = array($array1, $array2);

return $array3;
Brian Driscoll
  • 18,293
  • 2
  • 44
  • 61
  • Hi, but in my case, array1 doesn't has the same length of array2, for example, array1 has 30 items, however array2 has 90, besides, they havn't the same elements type, ayyar1(numeric), array2(varchar):( – Malloc Apr 25 '11 at 14:35
  • 1
    @Malek: From the web service side it doesn't matter how many elements are in each array nor what type of data they contain. PHP is not type-sensitive when creating arrays. – Brian Driscoll Apr 25 '11 at 14:38
  • 1
    to add on to my previous comment, `$array3` is an array containing two distinct `array` objects. So, the contents of each of `$array1` and `$array2` are independent of one another. – Brian Driscoll Apr 25 '11 at 14:41
  • ok, last question, from the iOS side, is it easy to parse the items of the two arrays separetly or i will have problems ? thx – Malloc Apr 25 '11 at 14:45
  • I will have to defer to someone who knows more than I about iOS programming, however my intuition is that it should not be difficult. – Brian Driscoll Apr 25 '11 at 14:47
  • 1
    you could use json, and output something like `{"keyone":[your first array],"keytwo":[your second array]}` and then in your ios code, you handle it as a dictionary of arrays – Robot Woods Apr 25 '11 at 14:48
1

it can return one array consisting of two array but not two array differently

jimy
  • 4,652
  • 3
  • 30
  • 49