What if you put $temp = $data->legs->leg[$k]['legId']; And then put that into $legrow[$temp]; Do you have anything in $temp? Jake > -----Original Message----- > From: rluckhurst@xxxxxxxxxxxxx [mailto:rluckhurst@xxxxxxxxxxxxx] > Sent: Saturday, March 24, 2007 11:27 PM > To: php-general@xxxxxxxxxxxxx > Subject: Array Question > > Hi All > > I am having a bit of trouble with PHP arrays and would > appreciate some help. > > I currently have the following piece of code > > $count=count($data->legs->leg); > $k=0; > while($k < $count) > { > > $legrow[$k]=$data->legs->leg[$k]['legId'].$VM.$data->legs->leg > [$k]['depApt'].$VM.$data->legs->leg[$k]['depTime'].$VM.$data-> > legs->leg[$k]['dstApt'].$VM.$data->legs->leg[$k]['arrTime'].$V > M.$data->legs->leg[$k]['equip'].$VM.$data->legs->leg[$k]['fNo' > ].$VM.$data->legs->leg[$k]['cr'].$VM.$data->legs->leg[$k]['mil > es'].$VM.$data->legs->leg[$k]['elapsed'].$VM.$data->legs->leg[ > $k]['meals'].$VM.$data->legs->leg[$k]['smoker'].$VM.$data->leg > s->leg[$k]['stops'].$VM.$data->legs->leg[$k]['eticket']; > > $k++; > } > > This works fine extracting the leg attributes from the legs array and > putting the data into a new legrow array delimited by $VM. > > I can do a print_r($legrow); and I get the rows displayed > correctly. I can > also access any row by using $legrow[n] where n is the key number. > > What I want to do is to find a way of indexing the array > using the legId > as the key if possible. In other words I want to extract the > row where the > legId has a particular value where I do not know the row key. > > I have been thinking that this might be possible with an > associative array > but my attempts to do this have not worked. > > What I have tried is as follows > > $count=count($data->legs->leg); > $k=0; > while($k < $count) > { > > $legrow["$data->legs->leg[$k]['legId']"]=$data->legs->leg[$k][ > 'depApt'].$VM.$data->legs->leg[$k]['depTime'].$VM.$data->legs- > >leg[$k]['dstApt'].$VM.$data->legs->leg[$k]['arrTime'].$VM.$da > ta->legs->leg[$k]['equip'].$VM.$data->legs->leg[$k]['fNo'].$VM > .$data->legs->leg[$k]['cr'].$VM.$data->legs->leg[$k]['miles']. > $VM.$data->legs->leg[$k]['elapsed'].$VM.$data->legs->leg[$k][' > meals'].$VM.$data->legs->leg[$k]['smoker'].$VM.$data->legs->le > g[$k]['stops'].$VM.$data->legs->leg[$k]['eticket']; > > $k++; > } > > My thinking is that the $data->legs->leg[$k]['legId'] is the > legId and I > might use that as a key. This however does not work. > > I would appreciate some guidance on how I might get this to work. > > Regards > > Richard Luckhurst > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- > No virus found in this incoming message. > Checked by AVG Free Edition. > Version: 7.5.446 / Virus Database: 268.18.17/731 - Release > Date: 3/23/2007 3:27 PM > > -- No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.5.446 / Virus Database: 268.18.17/731 - Release Date: 3/23/2007 3:27 PM -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php