|
Posted by Brent Baisley on 05/12/05 22:08
You're losing me hear without sample data, but I'll try.
Ideally your input array would be something like:
$result[] = array('id'=>23, 'text'=>'ok', 'relevance'=>2);
$result[] = array('id'=>42, 'text'=>'joel', 'relevance'=>1);
$result[] = array('id'=>23, 'text'=>'php', 'relevance'=>1);
Which gives you an array like:
print_r($result);
Array
(
[0] => Array
(
[id] => 23
[text] => ok
[relevance] => 2
)
[1] => Array
(
[id] => 42
[text] => joel
[relevance] => 1
)
[2] => Array
(
[id] => 23
[text] => php
[relevance] => 1
)
)
If you changed your array to be like this, then the original code won't
work.
You can cycle through the array like this:
foreach( $result as $resultItem) {
echo $resultItem['id'];
echo $resultItem['text'];
echo $resultItem['relevance'];
}
Hope that helps.
On May 12, 2005, at 10:13 AM, Merlin wrote:
> Hi Brent,
>
> thank you for that excellent example. I tried to get that working in a
> similar way but failed. However, you brought in knowledge which puts
> me into trouble. How can I output those arrays if they are the other
> way around?
> I used to do it like this:
> for ($i=0;$i<count($result[id]);$i++){
> echo $result[id][$i];
> echo $result[text][$i];
> }
>
> Now the array is the other way around, plus the array
> $resultSummary[$id]['id'] is not a 1,2,3 thing but there are missing
> values?!
> I need those Id's to create proper links from the output.
>
> Can you shed some more light on this?
>
> Thank you for your excellent help.
>
> Best regards, Merlin
>
--
Brent Baisley
Systems Architect
Landover Associates, Inc.
Search & Advisory Services for Advanced Technology Environments
p: 212.759.6400/800.759.0577
Navigation:
[Reply to this message]
|