parse array and pick information that is the same
Hey is an example of an array return from my soap response (i have no control over webservice)
[Names]
[Name]
[ID] => GH01
[F开发者_JAVA百科irst] => Greg
[Last] => Hobb
[DateAvailable] =>12.04.2011
[Contactable] => true
[Name]
[ID] => JM01
[First] => James
[Last] => Murr;
[DatesAvailable] => 12.04.2011
[Contactable] => true
[Name]
[ID] => GH01
[First] => Greg
[Last] => Hobb
[DateAvailable] => 13.04.2011
[Contactable] => true
[Name]
[ID] => JM01
[First] => James
[Last] => Murr;
[DatesAvailable] => 13.04.2011
[Contactable] => true
I cannot suitable form a loop that will take each name and group together the available dates. feeling so stupid. seems simple but i cannot get my head around it. perhaps one of your formula gurus can put me in the correct direction.
the code to get the object is as follows:
$result->Names;
how i would like to display:
Name: Greg Hobb Dates Avaiable: 12.04.2011 - 13.04.2011
hope that makes sense, i understasnd how to display them, just not grab them in the correct way.
It seems that the way you are implementing your array/data is unnecessary and overcomplicated. You have two array elements that are the same, except the date, so that you can take the two DatesAvailable (a start date and end date) and put them together to make your actual DatesAvailble.
In your Name array, just put a startDate and endDate field. That way each element is a different individual holding all data you need.
Here's some real choppy code (whipped it up quickly) of how you could take this, and create a new array like the one I described above:
$newArray; $flag; $num;
for($i = 0; $i < count($Names); $i++)
{
$flag = false;
for($c = 0; $c < count($newArray); $c++)
{
if($names[$i][$ID] == $newArray[$c][$ID])
{
$newArray[$c][$endDate] = $Names[$i][$datesAvailable];
$flag = true;
break;
}
}
if(!$flag)
{
//create a new element in $newArray. set ur ID, contact fields, etc.
$newArray[count($newArray)][$startDate] = $names[$i][$datesAvailable];
}
}
Hope this is of any help ><
精彩评论