Array Question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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'].$VM.$data->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->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.$data->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->leg[$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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux